Android 开发入门-详解4种基本布局
16lz
2021-01-23
3.3.1 线性布局 LinearLayout
使用 android:orientation 属性指定排列方向:
- vertical 垂直排列
- horizontal 水平排列,默认
<?xml version="1.0" encoding="utf-8"?>
使用 android:layout_gravity 指定控件在布局的对齐方式:
- top 顶部对齐
- center_vertical 垂直居中
- bottom 底部对齐
<?xml version="1.0" encoding="utf-8"?>
使用 android:layout_weight 以比例方式指定控件在布局的大小:
<?xml version="1.0" encoding="utf-8"?>
width 和 weight 组合使用:
<?xml version="1.0" encoding="utf-8"?>
3.3.2 相对布局 RelativeLayout
<?xml version="1.0" encoding="utf-8"?> # 左上角对齐 # 右上角对齐 # 居中对齐 # 左下角对齐 # 右下角对齐
相对控件进行定位布局
<?xml version="1.0" encoding="utf-8"?> # 居中对齐
其他相对于控件进行定位的属性:
- android:layout_alignLeft="@id/button3" 与button3左对齐
- android:layout_alignRight="@id/button3" 与button3右对齐
- android:layout_alignTop="@id/button3" 与button3上对齐
- android:layout_alignBottom="@id/button3" 与button3下对齐
3.3.3 帧布局 FrameLayout
默认情况下控件重叠显示:
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
3.3.4 百分比布局 PercentFrameLayout
LinearLayout 本身支持按比例指定控件大小,因此百分比布局只为 FrameLayout 和 RelativeLayout 进行了功能扩展。
# app/build.gradledependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:24.2.1' compile 'com.android.support:percent:24.2.1' #引入依赖}
<?xml version="1.0" encoding="utf-8"?>
更多相关文章
- 线性布局和相对布局的知识点
- android中textview控件中的文字的位置是如何调整的
- Android中设置控件可见与不可见详解
- Android 众多的布局属性详解[转]
- android xml界面布局常用属性概括
- Android下拉框控件Spinner的使用
- android之控件EditText学习