LinearLayout常用属性:
android:orientation=”vertival”
——该属性决定它子类空间的排列方式(vertical:垂直;horizontal:水平)
android:gravity=”center”
——该属性决定它子类XY的位置,要使用多个位置属性可以使用“|”隔开,如“center_horizontal | bottom”
Note:android:gravity与android:layout_gravity不一样!android:gravity用在父类控件来控制子类控件的布局,android:layout_gravity用于子类控件中来表示本身在父类控件中的位置,两种一般只使用一个。
同时,在子类控件中使用gravity表示子类控件文本的位置(此时其实也可以把文本看作是此控件的子类控件)

gravity常用的属性值有:
center_vertical:垂直(Y轴)居中
center_horizontal:水平(X轴)居中
center:水平垂直都居中
right:子类控件位于当前控件的右边
left:子类控件位于当前控件的左边
bottom:子类控件位于当前布局的下面

子类控件的属性:
android:layout_gravity:略(与gravity相同)
android:layout_weight=“1”指本身控件占当前父类容器的一个比例
Note:使用android:layout_weight时要注意上下排列时height属性要用wrap_content,左右排列时weight属性要使用wrap_content,否则比例很相反
示例:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <Button        android:layout_weight="2"        android:id="@+id/button1"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="Button" />    <Button        android:layout_weight="1"        android:id="@+id/button2"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="Button" />LinearLayout>

结果:

把android:layout_height改成match_parent

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <Button        android:layout_weight="2"        android:id="@+id/button1"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:text="Button1" />    <Button        android:layout_weight="1"        android:id="@+id/button2"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:text="Button2" />LinearLayout>

结果:

更多相关文章

  1. Android动画学习笔记-Android(安卓)Animation
  2. RecylcerView中的子view matchParent属性失效的问题
  3. 自定义控件其实很简单2/3
  4. Android(安卓)Animaition
  5. TextView英文自动换行解决方法
  6. EditText属性大全
  7. 安卓笔记:安卓控件属性大全
  8. GridLayout 使用总结
  9. android安装后控件拖不动问题解答

随机推荐

  1. 如何用命令(cmd)创建开启AVD
  2. 【Android 电量优化】电量优化 ( Battery
  3. 更改.android目录位置
  4. 去除警告 Android(安卓)NDK: WARNING: AP
  5. Android(安卓)Didn't find class "xxx某
  6. layui 上传图片 移动端 调用相机
  7. android的surfaceflinger原理讲解
  8. android   动态改变图片大小
  9. Android到Androidx记录
  10. android:windowSoftInputMode 介绍