layout_height="0dip"

本文详细解释了在Android布局中使用layout_weight与match_parent的原理与实践,通过实例展示了如何合理分配子视图的宽度比例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


Layout 中有写法如下:

     layout_height="0dip"  或者 layout_width="0dip"   

     这里的意思是不是用具体的数值来计算高度或者宽度,而是和layout_weight 一起来使用的。经常会有这样的写法: 同一个LinearLayout  (假设是横向的) 中 有几个view ,但是都不指定其具体的宽度,而是使用 layout_weight 参数来指定这几个view所占的比例。每个view所占的宽度的比例是自己的layout_weight 值和总的layout_weight的总和的比值。

例如:

<LinearLayoutandroid:id="@+id/remove_account_area"

       android:layout_width="match_parent"

       android:layout_height="wrap_content"

       android:orientation="horizontal"

       android:background="@android:drawable/bottom_bar">

        <View

           android:layout_width="0dip"

           android:layout_height="match_parent"

           android:layout_weight="1"/>

        <Buttonandroid:id="@+id/remove_account_button"

           android:layout_width="0dip"

           android:layout_height="wrap_content"

            android:layout_weight="2"

           android:layout_marginTop="5dip"

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

        <View

            android:layout_width="0dip"

           android:layout_height="match_parent"

           android:layout_weight="1"/>

   </LinearLayout>

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <Button android:id="@id/btn_test_helloworld" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:text="动态模板测试" android:layout_alignParentTop="true" /> <Button android:id="@id/btn_test_zixun" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:text="静态资源测试" android:layout_below="@id/btn_test_helloworld" /> <Button android:id="@id/btn_test_multibundle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:text="多bundle测试" android:layout_below="@id/btn_test_zixun" /> <Button android:id="@id/btn_test_invokemodule" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:text="测试scheme调起" android:layout_below="@id/btn_test_multibundle" /> <Button android:id="@id/btn_test_performance" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:text="性能测试入口" android:layout_below="@id/btn_test_invokemodule" /> <Button android:id="@id/btn_enter_dev" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:text="打开Debug设置页面" android:layout_below="@id/btn_test_performance" /> </RelativeLayout>。以上代码 添加什么可以实现 app界面 镜面翻转显示
06-10
我说了只要相对分布不要擅自修改:<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="16dp" android:background="#F5F5F5"> <LinearLayout android:layout_width="396dp" android:layout_height="22dp" android:background="#E0E0E0" android:gravity="center_vertical" android:orientation="horizontal"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" android:orientation="horizontal"> <ImageView android:layout_width="16dp" android:layout_height="16dp" android:contentDescription="Signal" android:src="@drawable/ic_signal" /> <ImageView android:layout_width="16dp" android:layout_height="16dp" android:layout_marginLeft="4dp" android:contentDescription="Battery" android:src="@drawable/ic_battery" /> </LinearLayout> </LinearLayout> <ImageView android:layout_width="48dp" android:layout_height="48dp" android:src="@drawable/Deco_App" android:contentDescription="Deco Logo" android:layout_gravity="center" android:layout_marginVertical="16dp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Welcome to Deco" android:textSize="20sp" android:textStyle="bold" android:textColor="#666666" android:layout_gravity="center" android:layout_marginBottom="16dp"/> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="I accept the Terms of Use and confirm that I have fully read and understood the Privacy Policy." android:textSize="12sp" android:textColor="#666666" android:buttonTint="#00C4CC" android:layout_marginBottom="8dp"/> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="I confirm to join the User Experience Improvement Program. I understand that I can opt out of the program any time." android:textSize="14sp" android:textColor="#666666" android:buttonTint="#00C4CC" android:layout_marginBottom="16dp"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Continue" android:textColor="#FFFFFF" android:background="@drawable/rounded_button" android:layout_gravity="center" android:textSize="16sp" android:layout_marginBottom="8dp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Disagree and Quit" android:layout_gravity="center" android:textSize="14sp" android:textColor="#00C4CC" /> </LinearLayout>
08-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值