不尊重我有这样的代码:重量比例在嵌套的LinearLayout
...
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="10">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="8">
<TextView android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
...
此代码嵌套在其他的LinearLayout的具有相同weightSum和重量。 我使用的SDK是1.6 Android。我不知道为什么分配给权重等于1的元素的空间量为何不同,如果我删除中间的TextView
。看起来,即使TextView
的文字大小(字符数)更多,重量为1的LinearLayout
也变小了。这怎么可能?
你的weightSum是10,但加起来你的体重我得到12.如果我没有弄错,这会造成问题。 – 2011-12-23 17:37:52
感谢您的回答..我很抱歉我的计划中的数字是正确的。 1 8 1.但仍然存在错误。 – 2011-12-27 09:23:42
即使这个LinearLayout没有嵌套,并且即使将包含的TextView设置为固定宽度(以dp表示),问题仍然存在! LinearLayout真的可以不包含任何内容吗?我只需要在那里放一个宽度的百分比,并假装这个宽度保持不变。 – 2011-12-27 09:46:01