I have 3 RadioButton in one line (linearLayout). I want to distribute them properly in the line, and not align all of them to the left, just as in this screenshot.
Currently it is displayed like this:
XML:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_below="#+id/linearLayout2"
android:layout_alignLeft="#+id/linearLayout2" android:id="#+id/linearLayout3">
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yes"
android:id="#+id/radioButton3" android:layout_gravity="center_horizontal|top" android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Maybe"
android:id="#+id/radioButton" android:layout_gravity="center_horizontal|top" android:checked="true"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No"
android:id="#+id/radioButton2" android:checked="false"/>
</RadioGroup>
</LinearLayout>
It is possible for classic buttons with 0dp (see here), but RadioButtons are invisible with this setting.
Is there an easy way to do that ?
Try this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout2"
android:layout_below="#+id/linearLayout2" >
<RadioGroup
android:layout_width="fill_parent"
android:weightSum="3"
android:layout_height="fill_parent" android:orientation="horizontal">
<RadioButton
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Yes"
android:id="#+id/radioButton3" android:checked="false"/>
<RadioButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Maybe"
android:layout_weight="1"
android:id="#+id/radioButton" android:checked="true"/>
<RadioButton
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="No"
android:id="#+id/radioButton2" android:checked="false"/>
</RadioGroup>
</LinearLayout>
Then you must have to use layout weight on you radio button:-
android:layout_weight beginner's question
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_below="#+id/linearLayout2"
android:layout_alignLeft="#+id/linearLayout2" android:id="#+id/linearLayout3">
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal">
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Yes"
android:id="#+id/radioButton3" android:layout_gravity="center_horizontal|top" android:checked="false"/>
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Maybe"
android:id="#+id/radioButton" android:layout_gravity="center_horizontal|top" android:checked="true"/>
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="No"
android:id="#+id/radioButton2" android:checked="false"/>
</RadioGroup>
</LinearLayout>
Related
Good afternoon,
I am trying to do an alignment like this one :
http://i.imgur.com/ArAEiZC.png
To do it I tried the following code :
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="0sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dark background"
android:textAppearance="#style/TextAppearance.AppCompat.Title" />
<RadioButton android:id="#+id/radio_darkbackground"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked"
android:layout_gravity="right"
android:gravity="right"/>
</LinearLayout>
As you can see, I put the layout_gravity and gravity on "right" but it does not work and look like this :
http://i.imgur.com/JDzwEJI.png
change your code to this:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dark background"
android:textAppearance="#style/TextAppearance.AppCompat.Title" />
<RadioButton android:id="#+id/radio_darkbackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked"
android:layout_gravity="right"/>
</FrameLayout>
Try This
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="0sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dark background"
android:textAppearance="#style/TextAppearance.AppCompat.Title" />
<RadioButton
android:id="#+id/radio_darkbackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="right"
android:gravity="right"
android:onClick="onRadioButtonClicked" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dark background"
android:textAppearance="#style/TextAppearance.AppCompat.Title"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"></View>
<RadioButton
android:id="#+id/radio_darkbackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked"/>
</LinearLayout>
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>
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
I have a layout which have RadioGroup and radiobuttons. it works but there are problems in display. I've shared the screenshots below.
Android 4.2.1 - 4.65 inch
Tablet Android 2.2 - 7 inch
Android 4.1.2 - 5.5 inch
code from the bottorbar layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:padding="3dp" android:gravity="center"
android:background="#drawable/bottom"
>
<RadioGroup
android:id="#+id/radioTur"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:measureWithLargestChild="true"
android:layout_gravity="center_vertical"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/rad_anasayfa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:button="#null"
android:gravity="center"
android:drawableTop="#drawable/anasayfabutton"
android:textColor="#color/White"
android:onClick="Anasayfa_TIKLA"
android:text="Anasayfa" >
</RadioButton>
<RadioButton
android:id="#+id/rad_haber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="#null"
android:gravity="center"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:drawableTop="#drawable/haberlerbutton"
android:textColor="#color/White"
android:onClick="Haber_TIKLA"
android:text="Haberler" >
</RadioButton>
<RadioButton
android:id="#+id/rad_duyuru"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="#null"
android:gravity="center"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:drawableTop="#drawable/duyurubutton"
android:textColor="#color/White"
android:onClick="Duyuru_TIKLA"
android:text="Duyurular" >
</RadioButton>
<RadioButton
android:id="#+id/rad_yemek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="#null"
android:gravity="center"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:drawableTop="#drawable/yemekbutton"
android:textColor="#color/White"
android:onClick="Yemek_TIKLA"
android:text="Yemek" >
</RadioButton>
<RadioButton
android:id="#+id/rad_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="#null"
android:gravity="center"
android:layout_weight="1"
android:onClick="Arama_TIKLA"
android:textAppearance="?android:attr/textAppearanceSmall"
android:drawableTop="#drawable/search_icon"
android:textColor="#color/White"
android:text="Arama" >
</RadioButton>
</RadioGroup>
</LinearLayout>
code from main layout
<?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="match_parent"
android:orientation="vertical"
android:id="#+id/AnaLayout"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
<include
android:id="#+id/cell1"
android:layout_height="wrap_content"
layout="#layout/bottombar"
/>
</LinearLayout>
</RelativeLayout>
I have been working for a few days.I didn't understand problem. Can someone help me ?
my icon
I found problem. The Problem is android:button="#null".
If the RadioButton has the android:button="#null" property the result will be:
If the RadioButton doesn't have the android:button="#null" property the result will be:
If the RadioButton has the android:button="#null" and android:background="#android:color/transparent" properties the result will be:
I added the android:background="#android:color/transparent" property to all RadioButtons and the problem was resolved.
Try out below layout.
I have assigned an equal weight to all the RadioButton's so that it will be adjust its size according to the screen size.
Its working fine now. Change your images accroding to you.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/aa"
android:gravity="center"
android:padding="3dp"
android:weightSum="1" >
<RadioGroup
android:id="#+id/radioTur"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/rad_anasayfa"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:button="#null"
android:gravity="center"
android:drawableTop="#drawable/ic_circle"
android:onClick="Anasayfa_TIKLA"
android:text="Anasayfa"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white" >
</RadioButton>
<RadioButton
android:id="#+id/rad_haber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:button="#null"
android:drawableTop="#drawable/ic_circle"
android:gravity="center"
android:onClick="Haber_TIKLA"
android:text="Haberler"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white" >
</RadioButton>
<RadioButton
android:id="#+id/rad_duyuru"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:button="#null"
android:drawableTop="#drawable/ic_circle"
android:gravity="center"
android:onClick="Duyuru_TIKLA"
android:text="Duyurular"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white" >
</RadioButton>
<RadioButton
android:id="#+id/rad_yemek"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:button="#null"
android:drawableTop="#drawable/ic_circle"
android:gravity="center"
android:onClick="Yemek_TIKLA"
android:text="Yemek"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white" >
</RadioButton>
<RadioButton
android:id="#+id/rad_search"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:button="#null"
android:drawableTop="#drawable/ic_circle"
android:gravity="center"
android:onClick="Arama_TIKLA"
android:text="Arama"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white" >
</RadioButton>
</RadioGroup>
</LinearLayout>
Try this..
Change the RadioGroup width as match_parent and try.
<RadioGroup
android:id="#+id/radioTur"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:measureWithLargestChild="true"
android:layout_gravity="center_vertical"
android:orientation="horizontal" >
and
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
<include
android:id="#+id/cell1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/bottombar"
/>
</LinearLayout>
Here is my full code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="3dp" >
<RadioGroup
android:id="#+id/radioTur"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:measureWithLargestChild="true"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/rad_anasayfa"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:drawableTop="#drawable/uP13v"
android:gravity="center"
android:onClick="Anasayfa_TIKLA"
android:text="Anasayfa"
android:textAppearance="?android:attr/textAppearanceSmall" >
</RadioButton>
<RadioButton
android:id="#+id/rad_haber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:drawableTop="#drawable/uP13v"
android:gravity="center"
android:onClick="Haber_TIKLA"
android:text="Haberler"
android:textAppearance="?android:attr/textAppearanceSmall" >
</RadioButton>
<RadioButton
android:id="#+id/rad_duyuru"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:drawableTop="#drawable/uP13v"
android:gravity="center"
android:onClick="Duyuru_TIKLA"
android:text="Duyurular"
android:textAppearance="?android:attr/textAppearanceSmall" >
</RadioButton>
<RadioButton
android:id="#+id/rad_yemek"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:drawableTop="#drawable/uP13v"
android:gravity="center"
android:onClick="Yemek_TIKLA"
android:text="Yemek"
android:textAppearance="?android:attr/textAppearanceSmall" >
</RadioButton>
<RadioButton
android:id="#+id/rad_search"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:drawableTop="#drawable/uP13v"
android:gravity="center"
android:onClick="Arama_TIKLA"
android:text="Arama"
android:textAppearance="?android:attr/textAppearanceSmall" >
</RadioButton>
</RadioGroup>
</LinearLayout>
I am trying to re arrange the radio buttons
I have a output
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>
to space the radio buttons in order as below !
Any ideas !
Copy the below code in your xml.I have changed weight distribution in layout
<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>
Hope this works
I would suggest not to use radioGroup for horizontal. i have found that there are issues on different devices when doing this (Galaxy Note 2 was one of these devices more recently).
Just use a horizontal linear layout, push it left with margins to align it and put buttons inside it which will have text and your background shape.
Then in code add click listeners to them, and have a way to save which button was last clicked.
you can have the state drawable contain a selected="true" state and call button.setSelected(true or false) to get it to show up as selected or deselected.