2013-03-16 50 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