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学习之LinearLayout_第1张图片

把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>

结果:
android学习之LinearLayout_第2张图片

更多相关文章

  1. RecylcerView中的子view matchParent属性失效的问题
  2. 自定义控件其实很简单2/3
  3. android安装后控件拖不动问题解答
  4. 【Android】Android中 Paint 字体、粗细等属性的一些设置
  5. 安卓笔记:安卓控件属性大全
  6. android layout属性 .
  7. Android 常用控件(三)学习笔记

随机推荐

  1. 【开发者必看】移动应用趋势洞察白皮书-
  2. 关于 Git 的 20 个面试题[每日前端夜话0x
  3. 三子棋
  4. 怎样在 Linux 中配置静态网络连接[每日前
  5. 坚持写博客的第二天,在敲代码的时候时间过
  6. 使用 TypeScript 和依赖注入实现一个聊天
  7. 分享崔庆才的一些学习经验和生活感悟
  8. 为什么要用 Node.js?[每日前端夜话0x77]
  9. pytest中print的坑
  10. 程序员到底该怎么给女朋友挑礼物