Layout布局之线性布局

  线性布局是按照水平或垂直的顺序将子元素(可以是控件或布局)依次按照顺序排列,每一个元素都位于前面一个元素之后。

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如果需要设置多个属性值,需要使用“|”进行

</pre>组合<p></p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; font-family: 'Helvetica Neue', Helvetica, Verdana, Arial, sans-serif; line-height: 23.8px;"><span style="margin: 0px; padding: 0px;">android:gravity 与 android:layout_gravity的区别<br style="margin: 0px; padding: 0px;" />android:gravity是指定本元素的子元素相对它的对齐方式。<br style="margin: 0px; padding: 0px;" />android:layout_gravity是指定本元素相对它的父元素的对齐方式。</span></p><p><span style="font-size:18px;">权重:剩余屏幕占有的比例</span></p><p><span style="font-size:18px;">if(wrap_content){</span></p><p><span style="font-size:18px;"> 权重值越大,占得屏幕比例越多,但小不过warp_contant</span></p><p><span style="font-size:18px;">}      </span></p><p><span style="font-size:18px;">if(match_parent){</span></p><p><span style="font-size:18px;"> 权重值越大,占得屏幕比例越小,但大大不过</span></p><p><span style="font-size:18px;">match_parent</span></p><p><span style="font-size:18px;">}</span></p><p><span style="font-size:18px;">权重公式<span style="background-color: rgb(255, 0, 0);">设置过权重的按钮的宽度=本身+剩余屏幕比例</span>wrap_content:登录设置过权重的按钮的宽度=wrap_content+(srceen-2*wrap_content)*1/3注册设置过权重的按钮的宽度=wrap_content+(srceen-2*wrap_content)*2/3match_parent:登录设置过权重的按钮的宽度=match_parent-screen*1/20001注册设置过权重的按钮的宽度=match_parent-screen*20000/20001</span></p><p></p><p> <img src="https://img-blog.csdn.net/20160918213523147?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" width="400" height="550" alt="" /></p><p><pre name="code" class="html"><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="horizontal" >

    <Button
       
        android:layout_width="wrap_content"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:text="btn1"
        android:background="#00ff00"
        android:textColor="#ff0000" />
    <Button
      
        android:layout_width="0dp"
        android:layout_weight="1999"
        android:layout_height="wrap_content"
        android:text="btn2"
        android:background="#00ff00"
        android:textColor="#ff0000" />

    <!-- <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#ff0000"
        android:text="文本提示框2"
    android:layout_marginRight="0dp"
        android:textColor="#0000ff" /> -->

</LinearLayout>


 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值