1.TableLayout表格布局
TableLayout的基本结构:
<TableLayout>
<TableRow>
...
</TableRow>
<TableRow>
...
</TableRow>
</TableLayout>
其中的两个重要属性:
<TableLayout>
<TableRow
android:layout_span="2">
...
</TableRow>
</TableLayout>
让一行控件占据两列
<TableLayout
android:stretchColumns="1">
...
</TableLayout>
将有该属性的一行进行拉伸,达到自动适应屏幕的作用。
2. 百分比布局
Android引入百分比布局来解决LinearLayout之外的其它布局因不能使用layout_weight属性带来的不便。
有PercentFrameLayout和PercentRelativeLayout两个布局(会分别继承FrameLayout和RelativeLayout相关的特性,如FrameLayout的控件默认都是放在布局左上角)。
百分比布局定义在support库中,在app/build.gradle文件的dependencies闭包中添加如下内容:
compile 'com.android.support:percent:24.2.1'
xml布局文件中的用法和界面效果见下图:
百分比布局由于不是内置在系统SDK中,做到了在所有Android版本上都能使用,另外,由于app:layout_heightPercent属性和app:layout_widthPercent属性是自定义属性,所以还必须用如下语句定义一个app的命名空间:
<android.support.percent.PercentFrameLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
......>
</android.support.percent.PercentFrameLayout>
未完待更