什么是LinearLayout:
线性布局是程序中最常见的一种布局方式,线性布局可以分为水平线性布局和垂直 线性布局两种,通过Android:orientation属性可以设置线性布局的方向
线性布局参数:
线性布局的一个参数:orientation
有两个值:vertical纵向 horizontal横向
上面写的是简单的两个按钮的控件
让按钮这两个 控件放在同一行里要wrap_content包裹内容,或者是适应内容
android:layout_width="wrap_content" android:layout_height="match_parent"
match_parent则是适应整个页面,如果
layout_width 使用match_parent就会是一下的结果,适应整个页面把另一个控件覆盖掉了
两个按钮是在左边的,把按钮移到右边我们需要用到gravity
Android:gravity:
内容居中:
android:gravity="center"
全局居中
android:layout_gravity="center"
Android:gravity:
该属性用于控制布局汇总控件的对齐方式,如果是没有子控件的控件设置此属性,表示其内容的对齐方式,比如说TextView里面文字的对齐方式,若是有子控件的控件设置此属性,则表示其子控件的对齐方式
什么叫做子控件呢,如下:
<Button android:layout_width="wrap_content" android:layout_height="match_parent" android:text="点击"/>
他下面是没有子控件的
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:text="点击"/>
而LinearLayout是包括了子控件的 ,也就是Button
也就是说,有子控件我们直接在LinearLayout上设置
android:gravity="right