问题
I can set android:shrinkColumns
and android:stretchColumns
at TableLayout
.
For example:
<TableLayout
android:shrinkColumns="2,3"
android:stretchColumns="1,3"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
So how do this properties affects columns?
回答1:
TableLayout can specify certain columns as shrinkable or stretchable by calling setColumnShrinkable()(xml:android:shrinkColumns) or setColumnStretchable()(xml:android:stretchColumns)
.
If marked as shrinkable, the column width can be shrunk to fit the table into its parent object. If marked as stretchable, it can expand in width to fit any extra space.
The total width of the table is defined by its parent container. It is important to remember that a column can be both shrinkable and stretchable .
For details information you may visit
https://developer.android.com/reference/android/widget/TableLayout.html
回答2:
maybe this can help
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="2,3"
android:stretchColumns="1">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:background="@color/red"
android:text="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:background="@color/green"
android:text="2" />
<TextView
android:layout_width="wrap_content"
android:background="@color/blue"
android:layout_height="wrap_content"
android:layout_column="1"
android:text="3" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:background="@color/red"
android:text="4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:background="@color/green"
android:text="5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:background="@color/blue"
android:text="6" />
</TableRow>
</TableLayout>
Explanations:
android:shrinkColumns="2,3"
android:stretchColumns="1"
Means that the columns 2 and 3 will be shrunk, and the column 1 will be stretched
android:shrinkColumns="3"
android:stretchColumns="1,2"
Means that the column 3 will be shrunk, and the columns 1 and 2 will be stretched
android:shrinkColumns="1"
android:stretchColumns="2,3"
Means that the column 3 will be shrunk, and the columns 1 and 2 will be stretched
android:stretchColumns="*" Means that all columns will be stretched evenly
android:shrinkColumns="*" Means that all columns will be shrunken evenly
来源:https://stackoverflow.com/questions/32331368/how-do-androidshrinkcolumns-and-androidstretchcolumns-work