3.2关于布局的那些事~
来源:互联网 发布:会声会影软件百度云 编辑:程序博客网 时间:2024/06/07 00:38
1.LinearLayout
android:orientation="horizontal"意味着要让LinearLayout中的控件在水平方向上依次排列,
="vertical"意味着在垂直方向上依次排列。
android:layout_gravity="center_vertical“指定控件在布局中的对齐方式为垂直方向上居中。
=“top”若android:orientation="horizontal",则意味着在垂直方向上居顶部。
=”bottom“意味着在垂直方向上居底部。
android:layout_weight允许我们使用比例的方式来指定控件的大小。
系统会先把 LinearLayout 下所有控件指定的 layout_weight 值相加, 得到一个总值,然后每个控件所占大小的比例就是用该控件的layout_weight值除以刚才算出的总值。
如:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" ><EditText android:id="@+id/input_message" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"/> <Button android:id="@+id/send" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"/></LinearLayout>Button控件和EditText控件的layout_weight值相加为2,故EditText和Button水平方向上分别占一半。
另,若某一控件a的没有指定layout_weight属性,则其他有layout_weight属性的控件b,c分享除了a剩余的空间。如:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" ><EditText android:id="@+id/input_message" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"/> <Button android:id="@+id/send" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"/> <Button android:id="@+id/test" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="test"/></LinearLayout>得到的界面就是:
2.RelativeLayout
相对于父布局
//左上
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
//右上
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
//中间
android:layout_centerInParent="true"
//左下
android:layout_alignParentBottom="true"114
android:layout_alignParentLeft="true"
//左下
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
相对于控件
2.1.
android:layout_above属性可以让一个控件位于另一个控件的上方,
android:layout_below表示让一个控件位于另一个控件的下方
android:layout_toLeftOf表示让一个控件位于另一个控件的左侧,
android:layout_toRightOf表示让一个控件位于另一个控件的右侧
如:
<Button android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/button4" android:layout_toLeftOf="@id/button4" android:text="left_to_button4" />button5就在button4的左上方
2.2
android:layout_alignRight表示一个控件的右边缘与另一个空间的右边缘对齐
<Button android:id="@+id/button6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/button5" android:text="I'm button6" />button6与button5的左边缘对齐
3.FrameLayout
所有的控件都会摆放在布局的左上角,即各个控件都是重叠在一起的~
4.TableLayout
TableLayout允许我们使用表格的方式来排列控件,
<TableRow>标签确定了一行,标签内的控件组成各列
android:layout_span="2"表示该控件占2列
android:stretchColumns="1"表示第如果表格不能占满整个屏幕,就将第二列进行拉伸,=“0”就将第一列进行拉伸。
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:stretchColumns="1"> <TableRow> <TextView android:id="@+id/account" android:layout_height="wrap_content" android:text="account" /> <EditText android:id="@+id/edit_account" android:layout_height="wrap_content" android:hint="put in your account" /> </TableRow> <TableRow> <TextView android:id="@+id/password" android:layout_height="wrap_content" android:text="password" /> <EditText android:id="@+id/edit_password" android:layout_height="wrap_content" android:hint="put in your password" /> </TableRow> <TableRow> <Button android:id="@+id/button7" android:layout_height="wrap_content" android:layout_span="2" android:text="submit" /> </TableRow></TableLayout>
- 3.2关于布局的那些事~
- 关于布局属性的那些事(笔记)
- 关于四种基本布局的那些事(笔记)
- 关于引入布局的那些事(笔记)
- 关于动态加载布局的那些事(笔记)
- 相对布局RelativeLayout的那些事
- 关于WAS的那些事....
- 关于foreach的那些事
- 关于成长的那些事
- 关于DOCTYPE的那些事
- 关于爱情的那些事。
- 关于http的那些事
- 关于年终奖的那些事
- 关于 DWR 的那些事
- 关于图片的那些事
- 关于补码的那些事
- 关于JSP的那些事
- 关于前端的那些事
- 笔记:TRULY_SPINACH(优酷播单:和我一起用Unity3D玩游戏)
- Linux学习笔记 文件读写小细节
- Android启动篇
- ubuntu linux下执行.sh文件
- Selective Ensemble of Decision Trees(周志华)
- 3.2关于布局的那些事~
- React-Native开发之原生模块封装(Android)升级版
- 0ss
- Day50、标准模板库、向量、迭代器、查找和排序、双端队列、列表、堆栈、队列和优先队列、映射、多重映射、集合、多重集合
- Greenplum自定义递归函数
- java错题集之try
- poj_2240 Arbitrage(Bellman_ford + map)
- 和哥一起学java之java学习大纲
- 百度云服务器搭建java+tomcat+mysql