寒假学干货之------LinearLayout.layout.weight

布局权重实例解析
本文通过一个具体的例子展示了如何使用布局权重来调整不同组件在界面上的显示比例。通过对LinearLayout的属性设置,使得开发者能够直观地理解weight属性的作用,并观察到不同权重值下布局的变化。

所有原始代码由这个大神写的--http://www.cnblogs.com/zhangs1986/archive/2013/01/17/2864237.html

layout/activity_main下

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.myprogram.text_two.MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="2"//这里是2 下面效果图
        android:orientation="horizontal">
        
        <Button...
<Button... <Button...
<Button... </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"//这里是1 android:orientation="vertical" > <Button... <Button... <Button... <Button... </LinearLayout> </LinearLayout>

接下来我们,在上面的weight赋值1,下面的赋值2

可以看见,第一种是2:1显示的1:2,是相反的。

转载于:https://www.cnblogs.com/mrAAron/p/5193923.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值