[英]Using layout_weight
Why the button on the middle dissapears? 为什么中间的按钮消失了? Instead of stretch to fill all the width of their parent?
而不是拉伸以填充其父代的所有宽度? And whereas when I set layout_height = 0dp it doest with height and fills their parent?
而当我设置layout_height = 0dp时,它没有高度并填充其父级?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
Since the linear layout orientation is vertical, only remaining height will be occupied if the layout_weight is "1", orientation is key here. 由于线性布局方向是垂直的,因此,如果layout_weight为“ 1”,则仅剩余高度将被占用,方向是关键。 if you want width to be shared, you might to change the orientation to "horizontal".
如果要共享宽度,则可以将方向更改为“水平”。 keep in mind that your children then will be placed horizontally.
请记住,您的孩子将被水平放置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.