如果直接在TableLayout中添加控件,那么控件将和父容器等宽
如果想让控件出现在同一行,那么这些控件的外层一定要加一对<TableRow>
在<TableRow>的控件中,宽度默认为wrap-content
stretchColumns : 可伸展的列
shrinkColumns : 可收缩的列
collapseColumns : 可隐藏的列
三个属性均是通过索引控制
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TableActivity"
android:stretchColumns="*">
<EditText></EditText>
<TableRow>
<Button
android:text="7"
></Button>
<Button
android:text="8"
></Button>
<Button
android:text="9"
></Button>
<Button
android:text="/"
></Button>
</TableRow>
<TableRow>
<Button
android:text="4"
></Button>
<Button
android:text="5"
></Button>
<Button
android:text="6"
></Button>
<Button
android:text="*"
></Button>
</TableRow>
<TableRow>
<Button
android:text="1"
></Button>
<Button
android:text="2"
></Button>
<Button
android:text="3"
></Button>
<Button
android:text="-"
></Button>
</TableRow>
<TableRow>
<Button
android:text="0"
></Button>
<Button
android:text="."
></Button>
<Button
android:text="+"
></Button>
<Button
android:text="="
></Button>
</TableRow>
<Button
android:text="clear"></Button>
</TableLayout>