2013-03-16 49 views
1

我想在用戶點擊一個項目後顯示一個列表項。但是,我注意到,當文字太多時,佈局會變得混亂。有時它被推到一半,有時它完全在屏幕的右側。我不明白爲什麼會發生這種情況。我該如何解決這個問題?請注意我在彈出的對話框中有完全相同的佈局,沒有任何問題。爲什麼我的TextView被移動?

這是我的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是:

推到右側的屏幕

enter image description here

太多的文字描述。熄滅屏幕

enter image description here

只推一半。

enter image description here

+0

我想你的佈局,但我可以重現你的問題。您可以嘗試將layout_weight = 1設置爲正確的視圖。 – Quanturium 2013-03-16 00:50:27

回答

2

TableLayout中列的大小由其最大內容給出。

您組織布局的方式,標題nameDetails是在第一列
您會注意到,在您不喜歡的情況下,第二列與標題的末尾整齊排列。

爲了解決這個問題,無論是移動的標題出表的佈局,或使用android:layout_span屬性來跨越這2列

+1

謝謝以後再說吧=) – 2013-03-16 01:59:46

1

我相信這一切,因爲你有你的標題@+id/nameDetails作爲表的第一行。當它確定表格左側的大小時,它包含此<textview>單元格的長度。

您可以將該textview移出tableview嗎?

+0

Ahhh我怎麼沒有看到 – 2013-03-16 01:59:17