《第一行代码Android》学习日记8
2015-10-24 21:41
239 查看
四种基本布局
1.线性布局LinearLayout
(1)这个布局中所包含的控件在线性方向上依次排列,通过android:orientation指定排列方向,vertical表示垂直方向排列,horizontal表示水平方向排列。Activity_main.xml代码如图
运行程序
(2)水平排列控件,其实内部控件的宽度不可指定为match_parent,以免单独一个控件将整个水平方向填满。运行程序
(3)修改activity_main.xml中的代码,通过指定android:layout_gravity的可选值来安排控件在布局中的对齐方式。当线性排列为水平方向时,垂直方向的对齐方式生效,当线性排列方向为垂直方向时,水平方向的对齐方式生效。指定Button1的对齐方式为top,Button2的对齐方式为center_vertical,Button3的对齐方式为bottom。
运行程序
(4)通过改变android:layout_weight的属性,改变界面中文本编辑框和发送按钮控件的布局。EditText和Button的android:layout_weight属性指定为1,表示两个控件将在水平方向上平分宽度。
运行程序
2.相对布局RelativeLayout
RelativeLayout通过相对定位的方式让控件出现在布局的任何位置。
(1)修改activity_main.xml中的代码,通过android:layout_alignParentLeft,android:layout_alignParentRight,android:layout_ParentRight,android:layout_alignParentBottom,android:layout_centerInParent等属性,来安排布局,使Button1和父布局的左上角对齐,Button2和父布局的右上角对齐,
Button3居中显示,Button4和父布局的左下角对齐,Button5和父布局的右上角对齐。
运行程序
(2)修改activity_main.xml的代码,应用android:layout_above属性,实现一个控件位于另一个控件的上方。应用android:layout_below属性,实现一个控件位于另一个控件下方。Android:layout_toLeftOf,Android:layout_toRightOf,实现一个控件位于另一个控件的左/右方。
运行程序
1.线性布局LinearLayout
(1)这个布局中所包含的控件在线性方向上依次排列,通过android:orientation指定排列方向,vertical表示垂直方向排列,horizontal表示水平方向排列。Activity_main.xml代码如图
运行程序
(2)水平排列控件,其实内部控件的宽度不可指定为match_parent,以免单独一个控件将整个水平方向填满。运行程序
(3)修改activity_main.xml中的代码,通过指定android:layout_gravity的可选值来安排控件在布局中的对齐方式。当线性排列为水平方向时,垂直方向的对齐方式生效,当线性排列方向为垂直方向时,水平方向的对齐方式生效。指定Button1的对齐方式为top,Button2的对齐方式为center_vertical,Button3的对齐方式为bottom。
运行程序
(4)通过改变android:layout_weight的属性,改变界面中文本编辑框和发送按钮控件的布局。EditText和Button的android:layout_weight属性指定为1,表示两个控件将在水平方向上平分宽度。
运行程序
2.相对布局RelativeLayout
RelativeLayout通过相对定位的方式让控件出现在布局的任何位置。
(1)修改activity_main.xml中的代码,通过android:layout_alignParentLeft,android:layout_alignParentRight,android:layout_ParentRight,android:layout_alignParentBottom,android:layout_centerInParent等属性,来安排布局,使Button1和父布局的左上角对齐,Button2和父布局的右上角对齐,
Button3居中显示,Button4和父布局的左下角对齐,Button5和父布局的右上角对齐。
运行程序
(2)修改activity_main.xml的代码,应用android:layout_above属性,实现一个控件位于另一个控件的上方。应用android:layout_below属性,实现一个控件位于另一个控件下方。Android:layout_toLeftOf,Android:layout_toRightOf,实现一个控件位于另一个控件的左/右方。
运行程序
相关文章推荐
- Android ANR
- Caused by: android.os.NetworkOnMainThreadException
- Android下HelloWorld项目的R.java文件介绍
- Android PopupWindow的使用和分析
- 《第一行代码Android》学习日记7
- android color.xml
- Android 的消息机制(Handler消息传递机制)
- Android编码规范03
- Android开发-控件
- AIDL 的理解与使用(一种android内部进程通信接口的描述语言)
- Android sdk配置
- Android学习(1)——接收和发送短信
- android简易计算器
- Android(1):Android创世纪(2)Activity启动流程(3)为控件绑定监听器
- android的xUtils框架
- 中国企业为啥不喜欢投资未来?
- android的R.java
- android的ListView显示
- android 设置返回键监听
- android---(xml、json解析)