简体   繁体   English

布局layout_weight和wrap_content

[英]layout layout_weight and wrap_content

Is it standard to use ( android:layout_weight="1" , android:layout_height="0dp" ) and ( android:layout_height="wrap_content" ) for two elements in one container with android:weightSum="1" 使用( android:layout_weight="1" , android:layout_height="0dp" )和( android:layout_height="wrap_content" )在具有android:weightSum="1"一个容器中用于两个元素android:weightSum="1"

I checked in android 4 , 6 , 8 and I didn't seen any problem but my question: 我在Android的4,6,8检查,我没有看到任何问题,但我的问题:

If one of elements feel the whole weightSum how other element can be visible ? 如果其中一个元素能感觉到整体重量,那么其他元素如何可见?

I use this layout to have a bottom menu in a layout that can be visible and invisible. 我使用此布局在可见和不可见的布局中都有一个底部菜单。

like this : 像这样 :

<LinearLayout
    android:orientation="vertical" 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1"
    >

 <LinearLayout
 android:orientation="vertical" 
 android:layout_weight="1"
 android:layout_width="match_parent"
 android:layout_height="0dp">
 </LinearLayout>

 <LinearLayout
 android:orientation="vertical" 
 android:layout_width="match_parent"
 android:layout_height="wrap_content">
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Ok"
                    />
 </LinearLayout>

</LinearLayout>

weight means a specified value from REMAINING space ...means that your view is 1 weight so every remaining space take your view...(remaining means all over view consider their height of width screen and after left space is remaining space in screen...counted by your linear layout oriantation ) that's all space consider in your 1 weight 重量是指剩余空间中的一个指定值...意味着您的视图为1重量,因此每个剩余空间都可以作为您的视图...(剩余表示整个视图均考虑其宽度屏幕的高度,而剩余空间则为屏幕中的剩余空间。 ..由您的线性布局排列()算出),所有空间都考虑在您的1重量中

refer this official document 请参阅此正式文件

I didn't seen any problem but my question is if one of elements feel the whole weightSum how other element can be visible ? 我没有看到任何问题,但我的问题是,其中一个元素是否能感觉到整个重量?

It's actually not using the whole weightsum. 实际上,它并没有使用整个权重。 Putting android:layout_weight="1" with height as 0 means that it will first check if any other layout want to use some height defined as wrap_content and after that whatever place exists it will make the remaining height of the targets first layout. android:layout_weight="1"的高度设置为0表示它将首先检查是否有其他布局要使用定义为wrap_content的高度,然后在任何存在的位置将目标的剩余高度作为第一个布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM