简体   繁体   中英

Android TableLayout width issue

I'm using TableLayout to display data. Text of the TextViews of the right column will be set when activity calls onCreate().

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" . but it still take a width of screen size to wrap data. How can I overcome from this issue?

替代文字

My 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.

BUt I would still recommend to use HorizontalScrollView for security purposes. If at all few chars are not visible, then horizontal scrollbar will help to manage that. XML text :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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