Reputation: 3905
I have a table which consists of 2 columns. The first column contains only an image whose width is fixed. The second column contains a text which can be very short or too long to fit in one line.
I want the table to fill the screen completely but not exceed it. The text can be divided into multiple lines if needed. Also, both columns should have some padding.
I was recommended to use weight 0 for the first column and weight 1 for the second column.
The first row of my table is:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rlMapDetail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
>
<TableRow>
<ImageView
android:id="@+id/imgAddress"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/map_address_detail"
android:layout_weight="0"
android:padding="5dp"
/>
<TextView
android:id="@+id/txtAddress"
android:textColor="@color/black_gray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|left"
android:singleLine="false"
android:inputType="textMultiLine"
android:layout_weight="1"
android:padding="5dp"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
/>
</TableRow>
The total width of the TableLayout exceeds the screen size, thus I have problem with following rows of the table.
Upvotes: 1
Views: 491
Reputation: 1291
I don't think you should provide weight as imageview has fixed width. You need to set width match parent to textview.
Upvotes: 0
Reputation: 3905
I finally found the solution to this problem was adding:
android:stretchColumns="1"
android:shrinkColumns="1"
to the TableLayout
Upvotes: 3