Reputation: 13733
I have a TableView with some table rows. one of them is this (I have 2 of this structure in the table):
<TableRow
android:id="@+id/trTimeSettingEndTime"
android:gravity="center_vertical"
android:paddingTop="10dp"
android:paddingBottom="3dp">
<ImageView
android:id="@+id/imageView2"
android:layout_width="35dp"
android:layout_height="35dp"
android:paddingRight="10dp"
android:src="@android:drawable/ic_menu_recent_history" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp"
android:text="Start Time" />
<TextView
android:id="@+id/tvTimeSettingEndTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="22dp"
android:text="00:00"
android:textColor="@color/dark_gray" />
</TableRow>
the image is at the right size. the middle textview takes out all the available space and the right textview width is it's content.
first thing I don't understand is why is the middle textview takes out all the space?
second, when I change tvTimeSettingEndTime textview from code and it's a bit longer then the text break a line instead of adjusting it's width.
can someone explain why is the middle on taking most of the space?
how can I make it that the third line would adjust it's width according to the text I put into it from code?
Thanks
Upvotes: 1
Views: 1164
Reputation: 6438
It sounds like you want the first column to be a static width (already working), the 3rd column to be the width of the contents (wrap_content), and the 2nd column to fill the available space. If so, try using a weight + 0dp width for the 2nd column, and wrap_content for the 3rd column.
<TableRow
android:id="@+id/trTimeSettingEndTime"
android:gravity="center_vertical"
android:paddingTop="10dp"
android:paddingBottom="3dp">
<ImageView
android:id="@+id/imageView2"
android:layout_width="35dp"
android:layout_height="35dp"
android:paddingRight="10dp"
android:src="@android:drawable/ic_menu_recent_history" />
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:weight="1"
android:layout_height="wrap_content"
android:textSize="16dp"
android:text="Start Time" />
<TextView
android:id="@+id/tvTimeSettingEndTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22dp"
android:text="00:00"
android:textColor="@color/dark_gray" />
</TableRow>
If you want the 2nd and 3rd to be equal widths, set them both to weight=1 and width=0dp.
Also keep in mind a TableLayout will force columns to be the same width for each row, if you are looking for each row's columns to size independently, try using two horizontal LinearLayouts instead.
Upvotes: 2