安卓TableLayout宽度问题

4
我正在使用TableLayout来展示数据。 右列TextView的文本将在activity调用onCreate()时设置。
现在,如下图所示,我的地址文本可能很长,应该进行换行。 因此,我设置了android:layout_width="wrap_content"。但它仍然需要屏幕大小的宽度来换行数据。 我该如何解决这个问题?
我的xml:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5px">
    <TableRow>
        <TextView android:text="Job#"
            android:paddingRight="5px" />
        <TextView android:id="@+id/DetailJobNo" />
    </TableRow>
    <TableRow>
        <TextView android:text="Address"
            android:paddingRight="5px" />
        <TextView android:id="@+id/DetailAddress"
            android:layout_width="wrap_content"
            android:text="Address Address Address Address Address Address Address Address "/>
    </TableRow>
</TableLayout>
3个回答

6
android:shrinkColumns="1"添加到TableLayout中可以解决我的问题。

0

@维卡斯,很好你解决了问题。

但出于安全考虑,我仍然建议使用HorizontalScrollView。如果某些字符不可见,则水平滚动条将有助于管理。XML文本:

<HorizontalScrollView android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp" android:layout_marginBottom="10dp" >

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"   
android:layout_width="fill_parent"   
android:layout_height="fill_parent"   
android:padding="5px">   
  ......
  ......
  ADD YOUR ROWS 
 </TableLayout>       
</HorizontalScrollView>

始终关注意料之外的情况是更好的选择。


0

好的,看起来你解决了问题!干杯,indyfromoz - indyfromoz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接