【问题标题】:Android TableLayout width issueAndroid TableLayout宽度问题
【发布时间】:2011-01-07 07:07:53
【问题描述】:

我正在使用 TableLayout 来显示数据。 活动调用onCreate()时会设置右列TextView的文本。

现在,正如您在下图中看到的那样,我的地址文本可能很长并且应该被换行。 所以我设置了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>

【问题讨论】:

    标签: android android-layout android-tablelayout


    【解决方案1】:

    android:shrinkColumns="1" 添加到 TableLayout 解决了我的问题。

    【讨论】:

      【解决方案2】:

      您可以尝试将 setHorizontallyScrolling 设置为 DetailAdress TextView 为 false 吗?

      【讨论】:

      • 好的,看来你的问题已经解决了!干杯,indyfromoz
      【解决方案3】:

      @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>
      

      处理意外总是更好。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-01-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多