Show many radio buttons - android

I have 7 radio buttons under one radio group. I rendered them horizontally using orientation = "horizontal". But only 4 can be visible at a time, rest are not.
Is there any way that I could show rest of them in second row while keeping all these 'Radiobuttons' in one 'RadioGroup`?
In case you need my code -
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.5 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2.5 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2.5 BHK" />
</RadioGroup>

You can't place RadioButtons at different places on the screen while keeping them in the same RadioGroup. You can't keep them in different rows either (like you want to achieve). Yes, I hate it too.
You can make checkboxes intead, place them the way you want, and then use setOnCheckedChangedListener on each of them. So if one of them is checked, call setChecked(false) on the others.
Use custom drawable so that they look like radio buttons and not checkboxes.

You can use scrollview inside a radio group like this
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<HorizontalScrollView
android:id="#+id/ScrlView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.5 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2.5 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2.5 BHK" />
</ScrollView>
</RadioGroup>

I guess, there is not enough place for all of them. Try to set android:layout_width="0dp" and android:layout_weight="1" to all RadioButtons. But it can be not very beautiful.

Try to set width for all Radiobutton
android:layout_width="0dp"
And also add android:layout_weight="1" for every Radio Button.
ex
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="1 BHK"
android:layout_weight="1"/>

Replace below code from your xml code
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.5 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2.5 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2.5 BHK" />
</RadioGroup>
</LinearLayout>
</HorizontalScrollView>

i also try this within RadioGroup and you can select only one at a time it works nice :
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton android:layout_height="match_parent" >
</RadioButton>
<RadioButton android:layout_height="match_parent" >
</RadioButton>
<RadioButton android:layout_height="match_parent" >
</RadioButton>
<RadioButton android:layout_height="match_parent" >
</RadioButton>
<RadioButton android:layout_height="match_parent" >
</RadioButton>
<RadioButton android:layout_height="match_parent" >
</RadioButton>
<RadioButton android:layout_height="match_parent" >
</RadioButton>
</RadioGroup>

My solution to this is to add a LinearLayout inside your RadioGroup layout.
I changed the orientation of the RadioGroup to vertical and added
two LinearLayout with horizontal orientation which will server as rows.
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.5 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2 BHK" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2.5 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3 BHK" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3.5 BHK" />
</LinearLayout>
</RadioGroup>

Related

Android vertically align text and widget

I'm using a text label and a radio group in a horizontal linear layout:
How do I set it so that the label (Sex) appears in the vertical center of the radio group? Currently it appears too high
The code for this portion of my layout is:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Sex:" />
<RadioGroup
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:id="#+id/input_button_male"
android:paddingRight="10dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:id="#+id/input_button_female"
android:paddingRight="10dp"/>
</RadioGroup>
</LinearLayout>
I think you could use android:layout_marginTop="??" within the Textview.
Alternately you could use android:gravity="center_vertical" within the Textview. Probably the latter.
i.e.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:layout_gravity="center_vertical"
android:text="Sex:" />
<RadioGroup
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:id="#+id/input_button_male"
android:paddingRight="10dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:id="#+id/input_button_female"
android:paddingRight="10dp"/>
</RadioGroup>
</LinearLayout>
Do you want like this then put in your textview below code
android:layout_gravity="center_vertical"
Check this out!
android:layout-width="0dp" not recommended! Prefer androd:layout-width="wrap_content"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_marginLeft="48dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_weight="0.4"
android:text="Sex :"
android:textSize="20sp" />
<RadioGroup
android:layout_marginRight="72dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:orientation="horizontal">
<RadioButton
android:id="#+id/input_button_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:text="Male" />
<RadioButton
android:id="#+id/input_button_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:text="Female" />
</RadioGroup>

RadioButton in multirow in single RadioGroup

I need to create design like radiobutton in multi-row in single radiogroup like this image .
I am using android:orientation="horizontal"
layout.xml
<RadioGroup
android:id="#+id/radiogroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/option1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:singleLine="false"
android:text="option1" />
<RadioButton
android:id="#+id/option2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:singleLine="false"
android:text="option2" />
<RadioButton
android:id="#+id/option3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:singleLine="false"
android:text="option3" />
<RadioButton
android:id="#+id/option4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:singleLine="false"
android:text="option4" />
<RadioButton
android:id="#+id/option5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:singleLine="false"
android:text="option5" />
<RadioButton
android:id="#+id/option6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:singleLine="false"
android:text="option6" />
</RadioGroup>
Thanks..
parent can be any like linear horizontal or relative(i'd prefer Linear Horizontal), inside that 3 TableRow childs,within each tableRow your RadioButtons. something like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<RadioGroup>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio1"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio2"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio3"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio4"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio5"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio6"/>
</LinearLayout>
</RadioGroup>
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<RadioGroup>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio1"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio2"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio3"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio4"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio5"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio6"/>
</LinearLayout>
</RadioGroup>
</TableRow>
What you are trying to achieve is possible.
You will have to subclass TableLayout and add the radio buttons programmatically
here is the link
refer this MATRIX RADIO BUTTONS
For screen width
Screen Width

Android:placing the radio buttons horizontally

Below is my Relative layout..i am trying to place the radio buttons above the edittext
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF" >
<ImageView
android:id="#+id/fbreplycancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/fbcancel" />
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="80dp"
android:layout_height="250dp"
android:layout_alignParentRight="true"
android:layout_below="#+id/fbcancel" >
<Spinner
android:id="#+id/replyspinner"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_alignLeft="#+id/fbshare"
android:layout_alignRight="#+id/fbshare"
android:layout_below="#+id/fbshare"
android:layout_marginTop="16dp"
android:drawSelectorOnTop="true"
android:entries="#array/fbcommentlist"
android:visibility="gone" />
<Button
android:id="#+id/fbshare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/fbbuttons"
android:text="#string/share" />
<ImageView
android:id="#+id/fbpeople"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/fbshare"
android:layout_centerHorizontal="true"
android:layout_marginBottom="19dp"
android:background="#drawable/people2"
android:drawSelectorOnTop="true"
android:paddingTop="20dp" />
<RadioButton
android:id="#+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="RadioButton" />
</RelativeLayout>
<View
android:layout_width="250dp"
android:layout_height="0.7dip"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/imageView1"
android:background="#3b5998" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/fbcancel"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingRight="2dp"
android:src="#drawable/askabud" />
<TextView
android:id="#+id/fbcommentpostedby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/fbedittext"
android:layout_alignRight="#+id/fbcommentdisplay"
android:layout_below="#+id/imageView1"
android:layout_marginTop="15dp"
android:textColor="#000000" />
<TextView
android:id="#+id/fbcommentdisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/fbedittext"
android:layout_below="#+id/fbcommentpostedby"
android:layout_toLeftOf="#+id/relativeLayout1"
android:textColor="#000000" />
<TextView
android:id="#+id/fbtextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_toLeftOf="#+id/fbreplycancel"
android:layout_toRightOf="#+id/imageView1"
android:text="#string/replyrecommend"
android:textSize="18sp"
android:textColor="#000000"/>
<TextView
android:id="#+id/fbplacename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/fbcommentdisplay"
android:layout_alignRight="#+id/fbcommentdisplay"
android:layout_below="#+id/fbcommentdisplay"
android:textColor="#000000" />
<EditText
android:id="#+id/fbedittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/fbplacename"
android:layout_marginLeft="19dp"
android:layout_marginTop="45dp"
android:layout_toLeftOf="#+id/relativeLayout1"
android:background="#drawable/roundcorners"
android:ems="10"
android:hint="#string/fbhint"
android:lines="6"
android:scrollHorizontally="true"
android:textSize="14sp"
android:windowSoftInputMode="stateHidden" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/fbplacename" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="30dp"
android:layout_height="30dp"
android:checked="true"
android:text="1"
/>
</RadioGroup>
<RadioGroup
android:id="#+id/radioGroup2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/radioGroup1"
android:layout_toLeftOf="#+id/relativeLayout1" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="26dp"
android:layout_height="wrap_content"
android:checked="true"
android:text="3" />
<RadioButton
android:id="#+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
</RadioGroup>
<RadioButton
android:id="#+id/radio1"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignTop="#+id/radioGroup2"
android:layout_toLeftOf="#+id/radioGroup2"
android:text="2" />
</RelativeLayout>
Iam facing a hard time to arrange them horizontally.Any help is appreciated.
To place a radiogroup (or any other view) above other just do:
android:layout_above="#+id/view_below"
To change the orientation just set:
android:orientation="horizontal"
And to give equal width to items make use of layout_weight:
<RadioGroup
android:id="#+id/radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_above="#+id/view_below" >
<RadioButton
android:id="#+id/radio1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:checked="true"
android:text="First" />
<RadioButton
android:id="#+id/radio2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Second" />
</RadioGroup>
You can use table layout instead of relative layout. Insert row into into table layout and place radio buttons inside table row..
For equal spacing follow following procedure
<TableRow
android:id="#+id/tableRow2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="50dp" >
<RadioButton
android:id="#+id/button2"
android:layout_width="5dp"
android:layout_height="60dp"
android:layout_weight="1"
android:text="#string/btnReject"
android:onClick="onCallRejectButton" />
<RadioButton
android:id="#+id/button1"
android:layout_width="5dp"
android:layout_height="60dp"
android:layout_weight="1
android:onClick="onCallAcceptButton"
android:text="#string/btnAccept" />
</TableRow>
android:orientation="horizontal" just do this. Type the orientation horizontal property to the radiogroup tag
<RadioGroup
android:id="#+id/radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:checked="true" />
<RadioButton
android:id="#+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>
You just need to put Radio Group orientation to horizontal.
<RadioGroup
android:id="#+id/radio_group_forgot_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
**android:orientation="horizontal"**
>

Beginner android developer - having difficulty with layouts

I have a button that's below a ScrollView, the button is set to align to the parents bottom. The scroll view is set to wrap_content for its height. Once the ScrollView is filled with content it appears beneath the button. How can I set it to not go behind the button, for the ScrollViewto end when the button begins?
I've tried placing android:layout_below in the bottom button, and when that didn't work I tried layout_above in the ScrollView for above the button. That last one caused my app to crash on start, no idea why. The first one once the ScrollView is longer than the screen it causes the button to be placed underneath with no way to access it.
Here's my XML file.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/light_blue"
android:padding="5dp"
tools:context=".MainActivity" >
<EditText
android:id="#+id/editText_query"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/queryPromt"
android:imeOptions="actionNext"
android:inputType="text"
android:textColor="#000" />
<EditText
android:id="#+id/editText_tag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editText_query"
android:layout_marginTop="10dp"
android:layout_toLeftOf="#+id/saveButton"
android:hint="#string/tagPrompt"
android:imeOptions="actionDone"
android:inputType="text" />
<Button
android:id="#id/saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/editText_query"
android:text="#string/save" />
<TextView
android:id="#+id/textView_taggedSearches"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignRight="#id/saveButton"
android:layout_below="#id/saveButton"
android:layout_marginTop="10dp"
android:background="#666"
android:gravity="center_horizontal"
android:text="#string/taggedSearches"
android:textColor="#FFF"
android:textSize="18sp" />
<ScrollView
android:id="#+id/scrollView_query"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/textView_taggedSearches"
android:padding="5dp" >
<TableLayout
android:id="#+id/tableLayout_query"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:stretchColumns="*" >
</TableLayout>
</ScrollView>
<Button
android:id="#+id/button_clearTags"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/clearTags" />
</RelativeLayout>
Try adding
android:layout_below="#id/scrollView_query"
to the last button
You can use layout_weight for this. If you set layout_height to "0px" you can use layout_weight to distribute the remaining parent space between sibling items.
In this case you want the button to have its normal size, and the scrollview to occupy whatever space remains. This should give you the general idea:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</ScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
I did this before in my project. and here is my xml code. you can modify it as per your usage.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<TextView android:id="#+id/TextView01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="This text view should act as header " />
<ScrollView android:layout_marginBottom="50dip" android:id="#+id/ScrollView01" android:layout_height="wrap_content" android:layout_width="fill_parent">
<RadioGroup android:id="#+id/RadioGroup01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<RadioButton android:id="#+id/RadioButton01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="#+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="#+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="#+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="#+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="#+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="#+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="#+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="#+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="#+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="#+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="#+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="#+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="#+id/RadioButton11" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
</RadioGroup>
</ScrollView>
<RelativeLayout android:layout_marginTop="-50dip" android:gravity="bottom" android:layout_height="wrap_content" android:layout_width="fill_parent">
<TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1">
<TableRow>
<Button android:id="#+id/Button01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="One"/>
<Button android:id="#+id/Button01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Two" android:layout_gravity="center_vertical"/>
<Button android:id="#+id/Button01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Three" android:layout_gravity="right"/>
</TableRow>
</TableLayout>
</RelativeLayout>
</LinearLayout>

Radio Button with image as an option instead of text

How can i add radio buttons in android app with option as an image , not the text.. we can set the text to radio button by android:setText property. But i want an image to be displayed there and not the text.. Please help me?
How about this one using the property android:drawableRight?
<RadioGroup
android:id="#+id/maptype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/line1"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:drawableRight="#drawable/map" />
<RadioButton
android:id="#+id/satellite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="#drawable/sat" />
</RadioGroup>
use this:
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</RadioGroup>

Categories

Resources