简体   繁体   English

Android TableLayout宽度问题

[英]Android TableLayout width issue

I'm using TableLayout to display data. 我正在使用TableLayout来显示数据。 Text of the TextViews of the right column will be set when activity calls onCreate(). 当活动调用onCreate()时,将设置右列TextView的文本。

Now, as you can see in the following image that my address text can be long and it should be wrapped. 现在,正如您在下图中看到的那样,我的地址文本可以很长并且应该被包装。 So I set android:layout_width="wrap_content" . 所以我设置了android:layout_width="wrap_content" but it still take a width of screen size to wrap data. 但它仍然需要一个宽度的屏幕大小来包装数据。 How can I overcome from this issue? 我怎样才能克服这个问题?

替代文字

My xml: 我的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, its good that you have solved your problem. @Vikas,你解决了问题的好处。

BUt I would still recommend to use HorizontalScrollView for security purposes. BUt我仍然建议使用Horizo​​ntalScrollView来保证安全。 If at all few chars are not visible, then horizontal scrollbar will help to manage that. 如果所有少数字符都不可见,那么水平滚动条将有助于管理它。 XML text : 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>

Its always better to take care of the unexpected. 总是更好地照顾意外。

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

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