要点:

  • android:orientation=”vertical”垂直线性布局,”horizontal”水平线性布局
  • android:gravity=”top”(buttom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical、clip_horizontal)控制布局中控件的对齐方式。如果是没有子控件的控件设置此属性,表示其内容的对齐方式,比如说TextView里面文字的对齐方式;若是有子控件的控件设置此属性,则表示其子控件的对齐方式,gravity如果需要设置多个属性值,需要使用“|”进行组合
  • android:gravity 与 android:layout_gravity的区别
  • android:gravity是指定本元素的子元素相对它的对齐方式
  • android:layout_gravity是指定本元素相对它的父元素的对齐方式
  • android:layout_weight=”1”通过设置控件的layout_weight属性以控制各个控件在布局中的相对大小,线性布局会根据该控件layout_weight值与其所处布局中所有控件layout_weight值之和的比值为该控件分配占用的区域。在水平布局的LinearLayout中有两个Button,这两个Button的layout_weight属性值都为1,那么这两个按钮都会被拉伸到整个屏幕宽度的一半。如果layout_weight指为0,控件会按原大小显示,不会被拉伸;对于其余layout_weight属性值大于0的控件,系统将会减去layout_weight属性值为0的控件的宽度或者高度,再用剩余的宽度或高度按相应的比例来分配每一个控件显示的宽度或高度

例:

布局代码

"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical" android:layout_width="match_parent"    android:layout_height="match_parent">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="80dp">        <Button            android:text="1"            android:layout_weight="4"            android:layout_width="0dp"            android:layout_height="match_parent" />        <Button            android:text="2"            android:layout_weight="6"            android:layout_width="0dp"            android:layout_height="match_parent" />    LinearLayout>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="80dp">        <Button            android:text="3"            android:layout_weight="7"            android:layout_width="0dp"            android:layout_height="match_parent" />        <Button            android:text="4"            android:layout_weight="3"            android:layout_width="0dp"            android:layout_height="match_parent" />    LinearLayout>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="match_parent"        android:orientation="vertical">        <Button            android:text="5"            android:layout_weight="2"            android:gravity="left"            android:layout_width="match_parent"            android:layout_height="0dp" />        <Button            android:text="6"            android:layout_weight="6"            android:layout_width="match_parent"            android:layout_height="0dp" />        <Button            android:text="7"            android:layout_weight="2"            android:gravity="right"            android:layout_width="match_parent"            android:layout_height="0dp" />    LinearLayout>LinearLayout>

更多相关文章

  1. android中设置一些没有maxHeight属性控件的最高值
  2. [置顶] Android动态添加控件约束位置
  3. android 中imageview 与diallog综合应用猜牌游戏
  4. Android的简单组件总结
  5. Android中如何实现图像的闪动
  6. Android(安卓)属性android:visibilty
  7. Android(安卓)layout_alignBottom 注意事项
  8. Android
  9. Android(安卓)控件 —— ListView

随机推荐

  1. React-native中如何插入iconfont
  2. Android - 实现两端对齐的文字排版
  3. 干货!!!Android富文本实现图文混排
  4. 在Ubuntu上编译Android Gingerbread 2.3.
  5. # Android: ListView 学生管理
  6. android设备唯一码的获取,cpu号,mac地址
  7. eoe android客户端源码剖析(二)侧滑菜单Sli
  8. Retrofit 2.0 超能实践(一),okHttp完美支持H
  9. Android(安卓)JUnit test 进行自动化测试
  10. Android(安卓)USB 主机(Host)和配件(Accesso