温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

安卓中linearLayout下android_layout.weight的属性的详细介绍

发布时间:2020-08-27 15:44:03 来源:网络 阅读:462 作者:清甘茶 栏目:移动开发

weight属性,从字面上理解是比重的意思,是和布局里其他部件相比较而言的。

1:在状态设置再orientation为horizontal、宽度设置为fill_parent、比例一个设置为1,一个设置为2的时候,如截图所示:

安卓中linearLayout下android_layout.weight的属性的详细介绍

此时显示的状态是第一个长度和第二个长度的比例是2:1,就是第一个长度要长一些。

2:现在修改一下放置的状态,修改成垂直放置android:orientation="vertical",其他条件不变,

如下所示

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

   tools:context="com.Test0101_21.MainActivity$PlaceholderFragment" >


   <Button

       android:layout_width="fill_parent"

       android:layout_height="wrap_content"

       android:layout_weight="1"

       android:text="@string/hello_world" />

 <Button

       android:layout_width="fill_parent"

       android:layout_height="wrap_content"

       android:layout_weight="2"

       android:text="@string/hello" />

</LinearLayout>

其运行结果是部件以上下进行排列,第二个部件和第一个部件宽度的比例是2:1,


结论:在水平方向上,比重越大,所显示的面积就越大,比重越小,显示的面积就越小。

     在垂直方向上,比重越大,起显示的面积就越小,比重越小,起显示的面积就越大。

     在水平方向上和垂直方向上其作用是相反的。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI