TableLayout screen width issue for Android

I am using TableLayout to display data. The right-column TextViews text will be set when onCreate () activity calls.

Now, as you can see in the following image, my address text can be long and needs to be wrapped. So I set android:layout_width="wrap_content" . but data transfer still requires a screen width. How can I overcome this problem?

alt text

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> 
+4
source share
3 answers

Adding android:shrinkColumns="1" to TableLayout solves my problem.

+6
source

Can you set setHorizontallyScrolling on the DetailAdress TextView text to false?

0
source

@Vikas, it's good that you solved your problem.

BUt I would recommend using HorizontalScrollView for security purposes. If all characters are not visible, then a horizontal scrollbar will help to cope with this. 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> 

It is always better to take care of the unexpected.

0
source

Source: https://habr.com/ru/post/1334629/


All Articles