Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align radio buttons horizontally and vertically in the same radiogroup

Tags:

android

I would like to have radio buttons in one radiogroup divided into 2 columns and several rows.

So far, I have been able to divide them by putting LinearLayouts inside the radiogroup. The problem is that they are not exclusive when I click on them (I can check all of them at the same time). Is there a way to make them exclusive (besides a programmatic way)?

like image 589
Ales Avatar asked Jan 30 '12 11:01

Ales


People also ask

How do I align two radio buttons horizontally in CSS?

To make a horizontal radio button set, add the data-type="horizontal" to the fieldset . The framework will float the labels so they sit side-by-side on a line, hide the radio button icons and only round the left and right edges of the group.

How do you change a RadioGroup from horizontal to vertical?

Yes, there is a way. Drag a radio list widget to your screen, go to the Properties tab and select 'Orientation' -> Horizontal.

Should radio buttons be horizontal or vertical?

Vertical positioning of radio buttons is safer. Radio buttons are tiny in nature, and, thus, according to Fitts' law, they can be hard to click or tap.

Which code is correct for selecting radio button from RadioGroup?

here you go. Use getCheckedRadioButtonId() method on your RadioGroup to find out. It returns -1 when no RadioButton in the group is selected.


1 Answers

I came to this page with a slightly different question. I want to keep all my radio buttons horizontal. May this this will be helpful to someone. Setting the orientation will take care of placing all the radio buttons in a single row.

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

Note: if the components cross the screen then also it will place the components in same row. So some of your columns may be hidden in small screen phones. But you can create another layout file for small screens.

like image 150
Joseph Selvaraj Avatar answered Sep 19 '22 14:09

Joseph Selvaraj