Today, let's simply say that Android is not centered on the Tablelayout layout (table layout)
The table layout means to think of our layout as a table, primarily for arranging controls neatly
Let's look at a simple case
<Tablelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context= "Com.example.activitylife.MainActivity"Android:stretchcolumns="*"> <TableRowAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "One"android:gravity= "Center"Android:background= "@android: Color/holo_blue_dark"/> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Two"android:gravity= "Center"Android:background= "@android: Color/holo_green_dark"/> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "three"android:gravity= "Center"Android:background= "@android: Color/holo_blue_dark"/> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Four"android:gravity= "Center"Android:background= "@android: Color/holo_green_dark"/> </TableRow> </Tablelayout>
Here we can see an attribute Android:stretchcolumns
Here we need to know a few properties in Tablelayout
Android:stretchcolumns sets the columns that can be stretched. The column can stretch to the row direction, up to a full row.
Android:shrinkcolumns sets the columns that can be shrunk. When the column control has too much content and is already packed in the row, the contents of the child control are displayed in the columns direction.
Android:collapsecolumns sets the columns to hide.
After that, let's take a look at some simple examples of what you can do with tablelayout:
<Tablelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context= "Com.example.activitylife.MainActivity"Android:stretchcolumns="*"> <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "100DP"Android:background= "@android: Color/holo_blue_bright"android:textsize= "30DP"Android:text= "0"android:gravity= "Right|center"/> <TableRowAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:layout_weight= "1"> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:text= "1"/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:text= "2"/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:text= "3"/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:text="+"/> </TableRow> <TableRowAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:layout_weight= "1"> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:text= "4"/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:text= "5"/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:text= "6"/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:text="-"/> </TableRow> <TableRowAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:layout_weight= "1"> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:text= "7"/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:text= "8"/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:text= "9"/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:text="*"/> </TableRow> <TableRowAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:layout_weight= "1"> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:text= "0"/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:text="."/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:text="/"/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:text="="/> </TableRow> <TableRowAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:layout_weight= "1"> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:text="="Android:layout_span= "4"/> </TableRow> </Tablelayout>
:
Android Learning sixth chapter (layout one tablelayout)