我正在使用 TableLayout 来显示数据。当 Activity 调用 onCreate() 时,将设置右列 TextView 的文本。

现在,如下图所示,我的地址文本可能很长,应该换行。所以我设置 android:layout_width="wrap_content". 。但仍然需要屏幕大小的宽度来包装数据。我该如何克服这个问题?

alt text

我的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>
有帮助吗?

解决方案

添加 android:shrinkColumns="1" 要解决我的问题。

其他提示

你可以尝试设置一下吗 设置水平滚动DetailAdress TextView 为 false?

@Vikas,很高兴你解决了你的问题。

但出于安全目的,我仍然建议使用 Horizo​​ntalScrollView。如果有几个字符不可见,那么水平滚动条将有助于管理它。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>

处理好意外情况总是更好。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top