Reputation: 109
I am new in android development. I was reading TableLayout, Which have three major attributes
android:stretchColumns, android:collapseColumns & android:shrinkColumns.
After Some Research I got what exaclty meant by android:strechColumns but i am confused between collapseColumns and shrinkColumns. The official docs Saying.
android:shrinkColumns
The zero-based index of the columns to shrink. The column indices must be separated by a comma: 1, 2, 5. Illegal and duplicate indices are ignored. You can shrink all columns by using the value "*" instead. Note that a column can be marked stretchable and shrinkable at the same time.
android:collapseColumns
The zero-based index of the columns to collapse. The column indices must be separated by a comma: 1, 2, 5. Illegal and duplicate indices are ignored.
What is exactly mean by shrink and collapse .Could anyone tell me what is difference between them?
Upvotes: 4
Views: 3197
Reputation: 85
android:stretchColumns
The zero-based index of the columns to stretch. The column indices must be separated by a comma: 1, 2, 5. Illegal and duplicate indices are ignored. You can stretch all columns by using the value "*" instead. Note that a column can be marked stretchable and shrinkable at the same time.
android:shrinkColumns
The zero-based index of the columns to shrink. The column indices must be separated by a comma: 1, 2, 5. Illegal and duplicate indices are ignored. You can shrink all columns by using the value "*" instead. Note that a column can be marked stretchable and shrinkable at the same time.
android:collapseColumns
The zero-based index of the columns to collapse. The column indices must be separated by a comma: 1, 2, 5. Illegal and duplicate indices are ignored.
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="*"
android:background="@color/grey">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:background="@color/red"
android:textColor="@android:color/white"
android:textSize="30dp"
android:text="0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:textColor="@android:color/white"
android:textSize="30dp"
android:background="@color/green"
android:text="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:textColor="@android:color/white"
android:textSize="30dp"
android:background="@color/blue"
android:text="2" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:background="@color/red"
android:textColor="@android:color/white"
android:textSize="30dp"
android:text="0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:textColor="@android:color/white"
android:textSize="30dp"
android:background="@color/green"
android:text="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:textColor="@android:color/white"
android:textSize="30dp"
android:background="@color/blue"
android:text="2" />
</TableRow>
</TableLayout>
Explanations:
android:stretchColumns="*"
Means it stretch all columns equally according table layout width
android:shrinkColumns="*"
Means it shrink all columns
android:shrinkColumns="0,2"
android:stretchColumns="1"
Means column 0 and 2 are wrap contain and column 1 stretch into available width
android:stretchColumns="0,1,2"
android:shrinkColumns="1"
Means if column already stretch then shrink not apply
android:shrinkColumns="*"
android:collapseColumns="1"
android:collapseColumns means it hide given column
android:stretchColumns="*"
TextView :- android:layout_column="2"
Meanning if tablerow first column layout parameter not start with 0 then empty view added into row
android:stretchColumns="*"
android:collapseColumns="1"
TextView :- android:layout_column="2"
Means if tablerow first column layout parameter not start with 0 then empty view added into row but if you collapse column then added empty view not hide of that column index only hide added view by explicit view
Upvotes: 4
Reputation: 6547
Shrinking Columns
We can shrink or reduce the width of the column(s) using the android:shrinkColumns attribute in the TableLayout. We can specify either a single column or a comma delimited list of column numbers for this attribute. The content in the specified columns word-wraps to reduce their width.
Collapsing Columns
We can make the column(s) collapse or become invisible through the android:collapseColumns attribute in the TableLayout. We can specify one or more comma-delimited columns for this attribute. These columns are part of the table information but are invisible. We can also make column(s) visible and invisible through coding by passing the Boolean values false and true, respectively, to the setColumnCollapsed() method in the TableLayout
Upvotes: 2