安卓:想了解的android:layout_weight [英] Android: trying to understand android:layout_weight
问题描述
我试图将一个页面中的三个部分。我想这样做的百分比值,但不支持通过Android系统。相反,我必须使用的android:layout_weight
。但我很难理解它,得到它的权利。特别是如何实际尺寸被计算。有没有办法让一个百分比值(0..100%)在机器人:layout_weight
我经历了几例(见附件截图)来描述问题。彩色场均<的LinearLayout>
与安卓layout_height =FILL_PARENT
,因为我想全屏是那些之间进行分配。
案例1
好,简单。每个<的LinearLayout>
获得33%
案例2
跌宕?第一个(黄色)<的LinearLayout>
完全消失?为什么呢?
案例3
再次迷茫。黄<的LinearLayout>
又回来了。然而,这两个第一<的LinearLayout>
与较重变得越来越小?这是怎么回事?
案例4
我完全不知道这一切背后的数学的。
有没有办法得到一个百分比值(0..100%)出的android:layout_weight
当然。让他们加起来100。
有关你的百分比值,你想要的安卓:在
为的LinearLayout
个别项目layout_height 0px
。
I'm trying to divide a page in three parts. I'd like to do it in percentage values, however that is not supported by Android. Instead I have to use android:layout_weight
. But I have a hard time understanding it and getting it right. Especially how the actual size gets calculated. Is there a way to get a percentage value (0..100%) out of android:layout_weight
?
I went through a few cases (see attached screenshot) to describe the problems. The colored fields are all <LinearLayout>
with android:layout_height="fill_parent"
, because I want the full screen to be divided between those.
Case 1
Okay, simple. Every <LinearLayout>
gets 33%.
Case 2
Ups?! The first (yellow) <LinearLayout>
disappears completely? Why?
Case 3
Confused again. The yellow <LinearLayout>
is back. However, the two first <LinearLayout>
with the heavier weight get smaller? What is going on?
Case 4
I have absolutely no idea what the maths behind all this is.
Is there a way to get a percentage value (0..100%) out of android:layout_weight?
Sure. Make them add up to 100.
For your "percentage value", you want the android:layout_height
of the individual items within the LinearLayout
to be 0px
.
这篇关于安卓:想了解的android:layout_weight的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!