簡體   English   中英

是否可以讓單選按鈕彼此不相鄰但仍可在同一個單選組中工作?

[英]Can you have Radio Buttons that are not beside each other but still work in one radio group?

我想做的是在不同的圖片上有幾個單選按鈕,所以當你點擊那個單選按鈕時,它變成背景,如果我把單選按鈕放在一個單選組中,所有按鈕 go 就在彼此旁邊,但是我基本上在頁面的四個邊緣需要它們。 我在相對布局中有我的布局,但是當我移動一個單選按鈕時,它離開了單選組,無論如何要阻止它嗎? 謝謝邁克爾。

這是無線電組的代碼

 <RadioGroup
        android:id="@+id/PictureSelection"
        android:layout_width="wrap_content"
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textView1"
        android:layout_alignRight="@+id/Picture1" >

        <RadioButton
            android:id="@+id/radioButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/EditQuestion2"
            android:layout_alignRight="@+id/Picture1" />

        <RadioButton
            android:id="@+id/radioButton4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <RadioButton
            android:id="@+id/radioButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/Picture2"
            android:layout_alignRight="@+id/Picture2" />

        <RadioButton
            android:id="@+id/radioButton3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignRight="@+id/textView1"
            android:layout_alignTop="@+id/EditQuestion1" />
    </RadioGroup>

按鈕的位置無關緊要。 只要他們在同一組。 有可能當您“移動”它時,您可能不小心制作了一個新按鈕並將其添加到該位置? 您必須提供有關此問題的更多信息才能獲得明確的答案,例如一些代碼。

向單選按鈕組添加一個按鈕只不過是告訴機器所有按鈕都是對同一個“問題”的“答案”。 換句話說,它們都是一個選項的所有可能選擇。 您可以在整個頁面上放置按鈕,如果將它們分組,您將永遠不會選擇多個按鈕。 如果您有兩個按鈕組,則每次只能“打開”(選擇)每個組中的一個按鈕,因此您將有兩個按鈕處於活動狀態,等等。分組按鈕與定位無關。

更改單選按鈕的 position 不會影響單選按鈕是否分組,請確保在聲明單選按鈕組之前聲明所有按鈕,並在聲明組后將每個按鈕添加到組中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM