我有两个按钮,我想水平并排显示,但它们一起填满了手机的水平长度。高度是包装内容,没关系。我现在的问题是只显示一个按钮(在屏幕上拉伸(stretch))。
这是我的 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"/>
关于Android按钮布局 - 在整个屏幕上并排放置两个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7248957/