Android第十课;线性布局

preview

LinearLayout是线性布局控件,它包含的子控件将以横向或竖向的方式排列
常用属性:
android:orientation=”“——该属性决定它子类控件的排布方式(vertical-垂直;horizontal-水平)
android:gravity=”“————–该属性决定它子类的xy的位置:

center_vertical————垂直(Y轴)居中
center_horizontal———垂直(X轴)居中
center————————水平垂直都居中
right————————–子类控件位于当前布局的右边
left—————————子类控件位于当前布局的左边
bottom———————–子类控件位于当前布局的下面

android:layout_gravity=”“———–表示本身在当前父容器的XY的一个位置

layout_gravity是想在父布局里面改变位置的时候用的,
gravity是想改变自己内部东西位置是用的

android:gravity属性是对该view中内容的限定.比如一个button 上面的text. 你可以设置该textbutton内的位置.
android:layout_gravity是用来设置该view相对与父view 的位置.比如一个button 在linearlayout里,你想把该button放在linearlayout里靠左、靠右等位置就可以通过该属性设置. 

android:layout_weight=”“———–指本身控件占当前父容器的一个比例

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <Button
        android:text="Button"
        android:layout_gravity="bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button"
        android:layout_weight="2" />
    <Button
        android:text="Button"
        android:layout_gravity="bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button1"
        android:layout_weight="1" />
</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <Button
        android:text="Button"
        android:layout_gravity="bottom"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/button"
        android:layout_weight="2" />
    <Button
        android:text="Button"
        android:layout_gravity="bottom"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/button1"
        android:layout_weight="1" />
</LinearLayout>


这两个xml文件里面唯一区别就是一个是android:layout_height=”wrap_content”,一个是android:layout_height=”match_parent”,wrap_content
会使比例正常显示,而match_parent则会反转

exercise

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值