我正在使用一个简单的水平LinearLayout来使三个按钮并排放置,它们的宽度都相同。我通过以下XML代码实现这一点:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:baselineAligned="false" >
<Button
android:id="@+id/help"
style="android:buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/help" />
<Button
android:id="@+id/close"
style="android:buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/closemultigame" />
<Button
android:id="@+id/ok"
style="android:buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/restartmultigame" />
</LinearLayout>
现在的布局看起来像这样:![设计师的截图](https://istack.dev59.com/giBAB.webp)
添加:完整布局如下所示:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/activity_horizontal_margin" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:drawableLeft="@drawable/matchandfit"
android:drawablePadding="@dimen/activity_horizontal_margin"
android:gravity="center_vertical"
android:padding="@dimen/activity_horizontal_margin"
android:text="@string/multigameover"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/status"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/multigameresult"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:id="@+id/masterresult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/masterresultinfo"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:baselineAligned="false" >
<Button
android:id="@+id/help1"
style="android:buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/help" />
<Button
android:id="@+id/close1"
style="android:buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/closemultigame" />
<Button
android:id="@+id/ok1"
style="android:buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/restartmultigame" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
正如Wasim Ahmed所指出的那样,这是由于ScrollView导致的。现在我使用ScrollView来确保即使在小设备的横向模式下,按钮也始终可访问。(布局用于对话框)。是否有其他方法始终保持按钮可访问/可见?
解决方法: 我找到的解决方案或更好的解决方法是在封闭LinearLayout的末尾添加一个TextView。这个TextView在其高度的一半左右被垂直裁剪,但它不包含任何文本,因此没有人会注意到它。将一些填充添加到封闭LinearLayout的底部没有帮助。