我有两个按钮,我希望水平并排显示,但它们一起填充手机的水平长度.高度是包裹内容,这很好.我现在的问题是只显示一个按钮(在屏幕上伸展).
这是我的XML代码:
<LinearLayout
android:id="@+id/page_buttons"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
>
<Button
android:id="@+id/prevButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="PrevIoUs"
/>
<Button
android:id="@+id/nextButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Next"
/>
解决方法
更改按钮XML以包含layout_weight属性:
<Button android:id="@+id/nextButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Next"/>