2011-01-07 50 views
4

我正在使用TableLayout來顯示數據。 當活動調用onCreate()時,右列的TextView的文本將被設置。Android TableLayout寬度問題

現在,您可以在下圖中看到我的地址文本可以很長並且應該被包裹。 所以我設置了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> 

回答

6

添加android:shrinkColumns="1"到TableLayout解決了我的問題。

0

@Vikas,它很好,你已經解決了你的問題。

BUt我仍然建議使用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> 

它總是更好地照顧意外。