0

我正在使用 aDialog向用户展示一些选项。我夸大了xml某个按钮的内容。在横向模式下,按钮显示如下:土地对话

在纵向模式下,按钮显示在一行中。但由于屏幕无法容纳所有按钮,因此某些按钮未显示。我想要这样的纵向模式按钮:肖像对话框

这意味着响应。但我该怎么做?我的xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="@drawable/jinish" >

     <Button
            android:id="@+id/sound2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="2dp"
            android:layout_marginLeft="2dp"
            android:background="@drawable/sound_xml"/>

            <Button
            android:id="@+id/review2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="2dp"
            android:background="@drawable/review_xml"/>

            <Button
            android:id="@+id/instraction"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="2dp"
            android:background="@drawable/instraction_xml"/>            

            <Button
            android:id="@+id/solve"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/solve_xml"
            android:layout_marginRight="2dp"/>  

            <Button
            android:id="@+id/reset"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/reset_xml"
            android:layout_marginRight="2dp"/>

</LinearLayout>

和我的java代码:

private LinearLayout options_layout;
private Dialog options_show;

options_layout = (LinearLayout) getLayoutInflater().inflate(
                R.layout.puzzle_options, null);

options_show = new Dialog(this);
options_show.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
options_show.setContentView(options_layout);
options_show.setCancelable(true);
options_show.setCanceledOnTouchOutside(true);
options_show.getWindow().setBackgroundDrawable(new ColorDrawable(0));

options_show.show();
4

1 回答 1

0
  • 使用 a GridView,并将其列设置为一个维度:android:numColumns="@integer/num_columns"
  • 添加到您的维度声明(例如 values/dimens.xml):<integer name="num_columns">3</integer>
  • 添加另一个尺寸文件,方向设置为横向(例如 values-land/dimens.xml):<integer name="num_columns">6</integer>

现在,根据设备方向,Android 将选择 3 或 6 作为列数。

您将需要创建一个基本适配器来将数据绑定到GridView.

于 2013-06-11T21:30:11.137 回答