1、线性布局 <? xml version= "1.0" encoding= "utf-8" ?> < LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android :orientation= "horizontal" android :layout_width= "match_parent" android :layout_height= "match_parent" > < Button android :id= "@+id/button_1" android :layout_width= "wrap_content" android :layout_height= "wrap_content" android :text= "Button 1" /> LinearLayout >

(1)排列方向: android :orientation= "horizontal" 水平 android :orientation= "vertical" 垂直
(2)元素布局的对其方式: 对其方式,可选项为top、bottom、left、rirht、center, 中间可以用 | 来指定多个; android :layout_gravity= "bottom" 注意:如果是vertical,就只有水平上的对齐才会生效
(3)边距 android :layout_marginTop= "10dp"
(4)比例权重 android :layout_weight= "1" 在某一个方向上设置权重之后,原本的那个方向上的数量置为0dp < Button android :id= "@+id/button_1" android :layout_width= "0dp" android :layout_weight= "1" android :layout_height= "wrap_content" android :text= "Button 1" /> < Button android :id= "@+id/button_2" android :layout_width= "wrap_content" android :layout_height= "wrap_content" android :text= "Button 2" />

2、相对布局 (1)相对父布局 < Button android :id= "@+id/button_1" android :layout_width= "wrap_content" android :layout_height= "wrap_content" android :layout_alignParentTop= "true" android :layout_alignParentLeft= "true" android :text= "Button 1" /> android :layout_alignParentBottom= "true" android :layout_alignParentRight= "true"
android :layout_centerInParent= "true"
(2)相对控件布局 < Button android :id= "@+id/button_3" android :layout_width= "wrap_content" android :layout_height= "wrap_content" android :layout_centerInParent= "true" android :text= "Button 3" />
< Button android :id= "@+id/button_1" android :layout_width= "wrap_content" android :layout_height= "wrap_content" android :layout_above= "@id/button_3" android :layout_toLeftOf= "@id/button_3" android :text= "Button 1" />
android :layout_below= "@id/button_3" android :layout_toRightOf= "@id/button_3"



3、帧布局(略过) FrameLayout
4、百分比布局(新增布局)(PercentFrameLayout,PercentRelativeLayout) 打开app/build.gradle,在dependencies闭包中添加如下内容: dependencies { 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' }
然后在布局中使用 PercentFrameLayout <? xml version= "1.0" encoding= "utf-8" ?> < android.support.percent.PercentFrameLayout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: app = "http://schemas.android.com/apk/res-auto" android :layout_width= "match_parent" android :layout_height= "match_parent" >
< Button android :id= "@+id/button1" android :text= "Button 1" android :layout_gravity= "left|top" app :layout_widthPercent= "50%" app :layout_heightPercent= "50%" />
< Button android :id= "@+id/button2" android :text= "Button 2" android :layout_gravity= "right|top" app :layout_widthPercent= "50%" app :layout_heightPercent= "50%" />
< Button android :id= "@+id/button3" android :text= "Button 3" android :layout_gravity= "left|bottom" app :layout_widthPercent= "50%" app :layout_heightPercent= "50%" />
< Button android :id= "@+id/button4" android :text= "Button 4" android :layout_gravity= "right|bottom" app :layout_widthPercent= "50%" app :layout_heightPercent= "50%" /> android.support.percent.PercentFrameLayout >







更多相关文章

  1. Android(安卓)Studio [相对布局RelativeLayout]
  2. Android(安卓)点击赞时弹出+1向上弹出动画
  3. Android——实现在纯Java代码里写布局
  4. android 沉浸式状态栏的三种方法
  5. Android初一
  6. 探讨相对布局的重要特性和属性
  7. 浅谈RelativeLayout相对布局
  8. android 相对布局属性说明
  9. android TextView设置字过多长长度后面显示省略号失效

随机推荐

  1. android配置cocos2dx环境
  2. Tools属性Tools Attributes
  3. Android(安卓)- TextView添加图片
  4. 最新Android面试题整理 5月
  5. Windows和Linux中android SDK是否通用的
  6. 黑马程序员.Android攻城狮.JAVA基础.1.6.
  7. Android应用程序的入口Activity
  8. Android(安卓)获取传感器列表整理及简单
  9. tomcat搭建本地服务器 实现apk更新下载(An
  10. 【从源码看Android】01从Looper说起