繁体   English   中英

Android TableLayout宽度问题

[英]Android TableLayout width issue

我正在使用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>

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

你可以尝试设置setHorizo​​ntallyScrollingDetailAdress TextView的假?

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

总是更好地照顾意外。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM