Androidx学习笔记(6)--常见布局--线性布局
2016-01-19 20:00
411 查看
线性布局
LinearLayout指定各个节点的排列方向
android:orientation="horizontal"
设置右对齐
android:layout_gravity="right"
当竖直布局时,只能左右对齐和水平居中,顶部底部对齐竖直居中无效
当水平布局时,只能顶部底部对齐和竖直居中
使用match_parent时注意不要把其他组件顶出去
线性布局非常重要的一个属性:权重
android:layout_weight="1"
权重设置的是按比例分配剩余的空间,并且要设置layout_width或layout_height要为0
有一个布局方向,水平或者竖直 在竖直布局下,左对齐、右对齐,水平居中生效 在水平布局下,顶部对齐、底部对齐、竖直居中生效 权重:按比例分配屏幕的剩余宽度或者高度 |
示例:
布局代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_weight="1"android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal">
<TextView
android:layout_weight="1"android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#ff0000"
/>
<TextView
android:layout_weight="1"android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#ffffff"
/>
<TextView
android:layout_weight="1"android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#000000"
/>
<TextView
android:layout_weight="1"android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@android:color/darker_gray"
/>
</LinearLayout>
<LinearLayout
android:layout_weight="1"android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
>
<TextView
android:layout_weight="1"android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#00ff00"
/>
<TextView
android:layout_weight="1"android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@android:color/darker_gray"
/>
<TextView
android:layout_weight="1"android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#000000"
/>
<TextView
android:layout_weight="1"android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#ffcc0000"
/>
</LinearLayout>
</LinearLayout>
相关文章推荐
- Androidx学习笔记(5)--短信发送器
- Android加壳native实现
- 【Android测试】【第二节】性能——CPU时间片
- android monkey测试
- Android 线程池 工作调度
- android使用帧动画防止内存溢出工具类
- android 开发中的三元运算符【转】
- Android中sharedPreferences的用法
- android DownloadManager获取进度并显示(二)
- Android应用前后台切换的判断
- Android TextView之Html.fromHtml学习
- 小米2/2S刷基于Android 5.1.1的CM12.1系统完整教程
- android studio *.apk does not exist on disk
- Android开发方法数超过65535的解决办法
- Android 学习
- 基于android系统的加密文件系统设计
- Android写SD卡的坑
- 如何在Android Studio添加本地aar包引用
- Android应用程序安装包签名
- 浅析Android的Handler