3.3.1 线性布局 LinearLayout

使用 android:orientation 属性指定排列方向:

  • vertical 垂直排列
  • horizontal 水平排列,默认
<?xml version="1.0" encoding="utf-8"?>    

使用 android:layout_gravity 指定控件在布局的对齐方式:

  • top 顶部对齐
  • center_vertical 垂直居中
  • bottom 底部对齐
<?xml version="1.0" encoding="utf-8"?>    

使用 android:layout_weight 以比例方式指定控件在布局的大小:

<?xml version="1.0" encoding="utf-8"?>        

width 和 weight 组合使用:

<?xml version="1.0" encoding="utf-8"?>        

3.3.2 相对布局 RelativeLayout

<?xml version="1.0" encoding="utf-8"?>    # 左上角对齐    

相对控件进行定位布局

<?xml version="1.0" encoding="utf-8"?>    # 居中对齐    

其他相对于控件进行定位的属性:

  • android:layout_alignLeft="@id/button3" 与button3左对齐
  • android:layout_alignRight="@id/button3" 与button3右对齐
  • android:layout_alignTop="@id/button3" 与button3上对齐
  • android:layout_alignBottom="@id/button3" 与button3下对齐

3.3.3 帧布局 FrameLayout

默认情况下控件重叠显示:

<?xml version="1.0" encoding="utf-8"?>            
<?xml version="1.0" encoding="utf-8"?>            

3.3.4 百分比布局 PercentFrameLayout

LinearLayout 本身支持按比例指定控件大小,因此百分比布局只为 FrameLayout 和 RelativeLayout 进行了功能扩展。

# app/build.gradledependencies {    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'        #引入依赖}
<?xml version="1.0" encoding="utf-8"?>    

更多相关文章

  1. 线性布局和相对布局的知识点
  2. android中textview控件中的文字的位置是如何调整的
  3. Android中设置控件可见与不可见详解
  4. Android 众多的布局属性详解[转]
  5. android xml界面布局常用属性概括
  6. Android下拉框控件Spinner的使用
  7. android之控件EditText学习

随机推荐

  1. android studio中使用Lambda
  2. android 经常用到的一些工具类--SharedPr
  3. 安卓startService:让你彻底理解startServi
  4. Android问题集锦之十五:可笑的unauthorize
  5. Android非UI线程更新UI的几种方法
  6. 一个好用的android图片压缩工具类
  7. Android 图片处理工具类封装
  8. android 源码修改记录
  9. Android启动init.c
  10. Android 数据无限的List实现(滚动到底部,请