《第一行代码》笔记4—UI布局篇

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>


未完待更

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
禁止转载,如需转载请通过简信或评论联系作者。

推荐阅读更多精彩内容