Android 的UI 可以分为两类:
- ViewGroup容器: 内部可以承载、放置、添加View视图
- View视图(控件): TextView,Button,ImageView
四种主要ViewGroup容器:
- LinearLayout: 横着和竖着排序
- RelativeLayout: 以其他布局为参考来定位的布局
- FrameLayout: 分层布局
- ConstraintLayout
线性布局Linear Layout
属性 值 orientation (必填)
1. vertical
2. horizaontal
layout_width/layout_height (必填)
1. match_parent: 填充上级容器
2. wrap_content: 自适应大小
3. 自定义大小
background
backgroundTint (安卓高版本里,有些控件需要使用backgroundTint,比如按钮)
颜色(包括透明) gravity
当前控件相对当前容器的位置
center
horzontal_center
vertical_center
layout_gravity
当前容器相对于父容器的位置
center
horzontal_center
vertical_center
weight 按比例分配父容器剩余的宽度或高度

本文介绍了Android的基础UI布局,包括LinearLayout和RelativeLayout。LinearLayout允许控件按垂直或水平方向排列,支持width/height设置及gravity属性。RelativeLayout则根据其他布局定位子视图。此外,还讲解了如何在FrameLayout中实现控件背景的完全填充。
最低0.47元/天 解锁文章
1620

被折叠的 条评论
为什么被折叠?



