2013-03-16 3 views
1

Я пытаюсь отобразить один элемент списка после того, как пользователь нажмет на элемент. Тем не менее, я заметил, что макет испорчен, когда слишком много текста. Иногда его подталкивают наполовину, иногда он полностью находится в правой части экрана. Я не понимаю, почему это происходит. Как я могу решить эту проблему? Обратите внимание, что у меня точно такой же макет в всплывающем диалоге без проблем.Почему мои текстовые элементы перемещаются?

Это мой XML код:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <TableLayout 
     android:id="@+id/add_spot_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:shrinkColumns="1" 
     android:stretchColumns="1" > 

     <TableRow 
      android:layout_marginBottom="1sp" 
      android:layout_marginTop="2sp" > 

      <TextView 
       android:id="@+id/nameDetails" 
       android:layout_width="fill_parent" 
       android:textSize="25sp" 
       android:textStyle="bold" /> 
     </TableRow> 

     <!-- separator --> 

     <View 
      android:layout_width="fill_parent" 
      android:layout_height="1dp" 
      android:background="@android:color/darker_gray" /> 

     <TableRow 
      android:layout_marginBottom="2sp" 
      android:layout_marginTop="2sp" > 

      <TextView 
       android:layout_marginLeft="5sp" 
       android:text="@string/distance" 
       /> 

      <TextView android:id="@+id/distanceDetails" /> 
     </TableRow> 

     <TableRow 
      android:layout_marginBottom="2sp" 
      android:layout_marginTop="2sp" > 

      <TextView 
       android:layout_marginLeft="5sp" 
       android:text="@string/address" 
       /> 

      <TextView android:id="@+id/addrDetails" /> 
     </TableRow> 

     <TableRow 
      android:layout_marginBottom="2sp" 
      android:layout_marginTop="2sp" > 

      <TextView 
       android:layout_marginLeft="5sp" 
       android:text="@string/type" 
       /> 

      <TextView android:id="@+id/typeDetails" /> 
     </TableRow> 

     <TableRow 
      android:layout_marginBottom="2sp" 
      android:layout_marginTop="2sp" > 

      <TextView 
       android:layout_marginLeft="5sp" 
       android:text="@string/terrain" /> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" > 

       <RatingBar 
        android:id="@+id/terrainDetails" 
        style="?android:attr/ratingBarStyleSmall" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:isIndicator="true" 
        android:max="5" 
        android:numStars="5" 
        android:stepSize="1" /> 
      </RelativeLayout> 
     </TableRow> 

     <TableRow> 

      <TextView 
       android:layout_marginLeft="5sp" 
       android:text="@string/difficulty" /> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" > 

       <RatingBar 
        android:id="@+id/difficultyDetails" 
        style="?android:attr/ratingBarStyleSmall" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:isIndicator="true" 
        android:max="5" 
        android:numStars="5" 
        android:stepSize="0.1" /> 
      </RelativeLayout> 
     </TableRow> 

     <TableRow 
      android:layout_marginBottom="2sp" 
      android:layout_marginTop="2sp" > 

      <TextView 
       android:layout_marginLeft="5sp" 
       android:text="@string/description" /> 

      <TextView 
       android:id="@+id/descDetails" 
       android:gravity="top" 
       android:lines="2" 
       android:maxLines="2" 
       android:scrollHorizontally="false" /> 
     </TableRow> 

     <View 
      android:layout_width="fill_parent" 
      android:layout_height="1dp" 
      android:background="@android:color/darker_gray" /> 
    </TableLayout> 

</ScrollView> 

Вот несколько скриншотов, чтобы показать вам, что я имею в виду:

Что это должно быть:

enter image description here

Что не должен» t be:

Отправлено в правую сторону от экран

enter image description here

Слишком много текста в описании. Гаснет экран

enter image description here

толкаемых только половина пути.

enter image description here

+0

Я попробовал ваш макет, но я мог бы воспроизвести вашу проблему. Вы можете попробовать установить layout_weight = 1 в свои правильные представления. – Quanturium

ответ

2

Размер столбца в TableLayout определяется его наибольшим содержанием.

, как вы организовали свой макет, название nameDetails находится в первого столбца.
Вы заметите, что в тех случаях, когда вам не нравится, второй столбец аккуратно выровнен с концом вашего названия.

Чтобы решить эту проблему, либо переместить название из макета таблицы, или использовать атрибут android:layout_span, чтобы охватить его на 2 колонки

+1

Спасибо, я дам ему снимок позже =) –

1

Я считаю, что это происходит потому, что у вас есть свой титул @+id/nameDetails в качестве первой строки таблицы. Он включает длину этой ячейки <textview>, когда он определяет размер левой стороны таблицы.

Можете ли вы перенести это текстовое изображение из таблицы?

+0

Ahhh, как я не видел этого –

Смежные вопросы