0

ラジオボタンを再配置しようとしています

出力があります

ここに画像の説明を入力

search_page.xml

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="10dp"
        android:background="#E1E1E1"
        android:weightSum="1" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".25"
            android:text="City" />

        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:background="@drawable/rounded_edittext"
            android:layout_weight=".75" />
    </LinearLayout>

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="@android:color/black" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:onClick="selectDate"
        android:orientation="horizontal"
        android:padding="10dp"
        android:background="#E1E1E1"
        android:weightSum="1" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".25"
            android:text="date" />

        <EditText
            android:id="@+id/DATE_EDIT_TEXT_ID"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight=".75"
            android:background="@drawable/rounded_edittext"
            android:onClick="selectDate" />
    </LinearLayout>

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="@android:color/black" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="10dp"
        android:background="#E1E1E1"
        android:weightSum="1" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".25"
            android:text="type" />

        <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/radio0"
            android:background="@drawable/yourbuttonbackground"
            android:button="@android:color/transparent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="Breakfast" />

        <RadioButton
            android:id="@+id/radio1"
            android:background="@drawable/yourbuttonbackground"
            android:button="@android:color/transparent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Lunch" />
    </RadioGroup>

        <RadioButton
            android:id="@+id/radio2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/yourbuttonbackground"
            android:button="@android:color/transparent"
            android:text="Dinner" />

    </LinearLayout>

以下のようにラジオボタンを順番に並べます!

ここに画像の説明を入力

何か案は !

4

2 に答える 2

1

以下のコードを xml にコピーします。レイアウトの重量配分を変更しました

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#E1E1E1"
        android:orientation="horizontal"
        android:padding="10dp"
        android:weightSum="2.5" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="type" />

        <RadioGroup
            android:id="@+id/radioGroup1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="horizontal" >

            <RadioButton
                android:id="@+id/radio0"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="2dp"
                android:layout_weight=".5"
                android:background="@drawable/yourbuttonbackground"
                android:button="@android:color/transparent"
                android:checked="true"
                android:padding="5dp"
                android:text="Breakfast" />

            <RadioButton
                android:id="@+id/radio1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="2dp"
                android:layout_weight=".5"
                android:background="@drawable/yourbuttonbackground"
                android:button="@android:color/transparent"
                android:padding="5dp"
                android:text="Lunch" />
        </RadioGroup>

        <RadioButton
            android:id="@+id/radio2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="2dp"
            android:layout_weight=".5"
            android:background="@drawable/yourbuttonbackground"
            android:button="@android:color/transparent"
            android:padding="5dp"
            android:text="Dinner" />
    </LinearLayout>

これがうまくいくことを願っています

于 2013-10-04T20:17:42.153 に答える
1

水平には radioGroup を使用しないことをお勧めします。これを行うと、さまざまなデバイスで問題が発生することがわかりました(Galaxy Note 2は、最近これらのデバイスの1つでした)。

水平の線形レイアウトを使用し、余白を残して左に押して整列させ、テキストと背景の形状を持つボタンをその中に配置します。

次に、コードでクリックリスナーを追加し、最後にクリックされたボタンを保存する方法を用意します。

ステート ドローアブルに selected="true" ステートを含め、button.setSelected(true または false) を呼び出して、選択または選択解除として表示することができます。

于 2013-10-04T20:17:51.287 に答える