Android(安卓)常用布局
16lz
2021-12-04
文章目录
- 常用布局
- LinearLayout
- RelativeLayout
- FrameLayout
- GridLayout
常用布局
- FrameLayout:帧布局
- LinearLayout:线性布局
- RelativeLayout:相对布局
- GridLayout:网格布局
公有属性 | 说明 |
---|---|
layout_width layout_height | 布局宽高 |
layout_margin layout_marginTop layout_marginBottom layout_marginRight layout_marginLeft | 布局外边距 |
padding paddingLeft paddingTop paddingRight paddingBottom | 布局内边距 |
gravity | 控制布局内的子控件位置 |
layout_gravity | 当前控件相对于父控件的位置 只用用于LinearLayout和FrameLayout |
LinearLayout
特有属性 | 说明 |
---|---|
orientation | 布局内控件的排序方式:水平、垂直 |
layout_weight | 将布局的控件按权重比例分配 |
RelativeLayout
特有属性 | 说明 |
---|---|
layout_alignTop layout_alignParentLeft layout_alignParentRight layout_alignParentBottom layout_centerInParent layout_centerHorizontal layout_centerVertical | 当前控件相对于父控件的位置 |
layout_above layout_below layout_toLeftOf layout_toRightOf | 当前控件在x控件的位置 |
layout_alignLeft layout_alignTop layout_alignRight layout_alignBottom | 当前控件与x控件的对齐位置 |
FrameLayout
只具备公有属性
GridLayout
特有属性 | 说明 |
---|---|
columnCount rowCount | 网格布局最大列数和最大行数 |
orientation | 布局内控件的排列方式 |
layout_column layout_row | 指定单元格在第几列和第几行 |
layout_columnSpan layout_rowSpan | 指定单元格占据的列数和行数 |
layout_gravity | 指定单元格在布局中的位置 |
layout_columnWeight layout_rowWeight | 单元格的列权重和行权重 |
注意:使用layout_columnSpan
或layout_columnSpan
时需要使权限属性
<?xml version="1.0" encoding="utf-8"?><GridLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#e5e6e7" android:columnCount="4" android:orientation="horizontal" android:rowCount="7"> <EditText android:layout_rowWeight="3" android:layout_columnSpan="4" android:layout_columnWeight="2" android:layout_gravity="fill_horizontal" android:gravity="right|bottom" android:hint="输入数据..." /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowWeight="1" android:layout_columnSpan="2" android:layout_columnWeight="1" android:layout_margin="1dp" android:background="#fff" android:gravity="center" android:text="清空" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowWeight="1" android:layout_columnSpan="2" android:layout_columnWeight="1" android:layout_margin="1dp" android:background="#fff" android:gravity="center" android:text="删除" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowWeight="1" android:layout_columnWeight="1" android:layout_margin="1dp" android:background="#fff" android:gravity="center" android:text="1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowWeight="1" android:layout_columnWeight="1" android:layout_margin="1dp" android:background="#fff" android:gravity="center" android:text="2" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowWeight="1" android:layout_columnWeight="1" android:layout_margin="1dp" android:background="#fff" android:gravity="center" android:text="3" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowWeight="1" android:layout_columnWeight="1" android:layout_margin="1dp" android:background="#fff" android:gravity="center" android:text="/" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowWeight="1" android:layout_columnWeight="1" android:layout_margin="1dp" android:background="#fff" android:gravity="center" android:text="4" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowWeight="1" android:layout_columnWeight="1" android:layout_margin="1dp" android:background="#fff" android:gravity="center" android:text="5" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowWeight="1" android:layout_columnWeight="1" android:layout_margin="1dp" android:background="#fff" android:gravity="center" android:text="6" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowWeight="1" android:layout_columnWeight="1" android:layout_margin="1dp" android:background="#fff" android:gravity="center" android:text="*" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowWeight="1" android:layout_columnWeight="1" android:layout_margin="1dp" android:background="#fff" android:gravity="center" android:text="7" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowWeight="1" android:layout_columnWeight="1" android:layout_margin="1dp" android:background="#fff" android:gravity="center" android:text="8" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowWeight="1" android:layout_columnWeight="1" android:layout_margin="1dp" android:background="#fff" android:gravity="center" android:text="9" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowWeight="1" android:layout_columnWeight="1" android:layout_margin="1dp" android:background="#fff" android:gravity="center" android:text="-" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowWeight="1" android:layout_columnSpan="2" android:layout_columnWeight="1" android:layout_margin="1dp" android:background="#fff" android:gravity="center" android:text="0" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowWeight="1" android:layout_columnWeight="1" android:layout_margin="1dp" android:background="#fff" android:gravity="center" android:text="." /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowSpan="2" android:layout_rowWeight="1" android:layout_columnWeight="1" android:layout_margin="1dp" android:background="#f5041d" android:gravity="center" android:text="+" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowWeight="1" android:layout_columnSpan="3" android:layout_columnWeight="1" android:layout_margin="1dp" android:background="#fff" android:gravity="center" android:text="=" /></GridLayout>
更多相关文章
- 利用View.inflate加载xml
- layout_gravity="bottom" 失效
- android installd分析
- 安卓巴士Android开发神贴整理
- Android布局属性详解
- Android实现自定义的 时间日期 控件
- Android(安卓)关于WebView的相关属性
- android TabWidget 位置
- android.inputmethodservice.KeyboardView 自定义键盘 字体大小