Android - Radio Group Button Text Position - android

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>

Related

Radiobutton on click event not working

image `
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:gravity="left"
android:text="Satisfied"
android:textSize="15dp"
android:textStyle="normal" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<com.example.rupertfernandes.itsforyou.progressutil.ProgressIndicator
android:id="#+id/determinate_progress_indicator1"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginLeft="30dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="150dp"
android:gravity="center"
android:text="Satisfied"
android:textColor="#7CFC00"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_margin="10dp"
android:background="#ffffff" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/questiontext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:padding="10dp"
android:text="Question of the Day"
android:textColor="#7CFC00"
android:textSize="20dp" />
<TextView
android:id="#+id/questiontextOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:padding="10dip"
android:text="Q-1. How are you feeling today ?"
android:textColor="#ff69b4"
android:textSize="15dp" />
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true">
<include
android:id="#+id/cell1"
layout="#layout/radiobutton"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="#+id/questiontextTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:padding="10dip"
android:text="Q-3. How is the day going on ?"
android:textColor="#ff69b4"
android:textSize="15dp" />
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true">
<include
android:id="#+id/cell1"
layout="#layout/radiobutton"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="#+id/questiontextThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:padding="10dip"
android:text="Q-4. How is the work going on ?"
android:textColor="#ff69b4"
android:textSize="15dp" />
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true">
<include
android:id="#+id/cell1"
layout="#layout/radiobutton"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="#+id/questiontextFour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:padding="10dip"
android:text="Q-5. How is the night going on ?"
android:textColor="#ff69b4"
android:textSize="15dp" />
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true">
<include
android:id="#+id/cell1"
layout="#layout/radiobutton"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:id="#+id/btnsubmitwellbeing"
android:layout_width="fill_parent"
android:background="#7CFC00"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Submit"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
below is the include code:
<?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:gravity="center"
android:padding="3dp"
android:weightSum="1" >
<RadioGroup
android:id="#+id/radioGroupWell"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/extremely_unsatisfied"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:button="#null"
android:gravity="center"
android:onClick="extremely_unsatisfied"
android:text="Extremely Unsatisfied"
android:drawableTop="#drawable/user_icon"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" >
</RadioButton>
<RadioButton
android:id="#+id/unsatisfied"
android:layout_width="0dp"
android:button="#null"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:drawableTop="#drawable/user_icon"
android:gravity="center"
android:onClick="unsatisfied"
android:text="Unsatisfied"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" >
</RadioButton>
<RadioButton
android:id="#+id/neutral"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:button="#null"
android:drawableTop="#drawable/user_icon"
android:gravity="center"
android:text="Neutral"
android:onClick="neutral"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" >
</RadioButton>
<RadioButton
android:id="#+id/satisfied"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:drawableTop="#drawable/user_icon"
android:gravity="center"
android:button="#null"
android:onClick="satisfied"
android:text="Satisfied"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" >
</RadioButton>
<RadioButton
android:id="#+id/extremly_satisfied"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:drawableTop="#drawable/user_icon"
android:gravity="center"
android:onClick="extremly unsatisfied"
android:text="Extremely Satisfied"
android:button="#null"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" >
</RadioButton>
</RadioGroup>
</LinearLayout>
`I have attached a file.
It has 5 radiobuttons in one row..and there are 5 such rows..the radiobuttons are inside a scroll view.
kindly help with xml file and the code as to how to check the radio buttons and also on click of submit the value in the circular progress bar should increase based on the user input in the radio buttonsthe image is as shown
You can't attach files here.
RadioButtons have an OnCheckChangedLister that does what you'd expect. Or you can call isChecked() to poll the value.

How to adjust space between radio button in android

In my android application using radio buttons to select screen view. I want radio button equally aligned horizontal. I tried layout xml shown below.
<?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="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Views"
android:paddingLeft="10dp"
android:textSize="20sp"
/>
<RadioGroup
android:id="#+id/radioView"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:measureWithLargestChild="true"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/radioViewSingle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:drawableRight="#drawable/single"
android:layout_weight="1"
android:checked="true" />
<RadioButton
android:id="#+id/radioView2by2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableRight="#drawable/view2x2" />
<RadioButton
android:id="#+id/radioView3by3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableRight="#drawable/view3x3" />
<RadioButton
android:id="#+id/radioView4by4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableRight="#drawable/view4x4" />
</RadioGroup>
</LinearLayout>
output obtained using above xml code
But i expecting below output
Thanks in advance
Instead of using android:drawableRight, use android:drawableLeft.
I just tested this and it is working as expected
Remove android:layout_weight="1" for all RadioButtons and set android:layout_width="0dp" to android:layout_width="wrap_content"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="Views"
android:textSize="20sp" />
<RadioGroup
android:id="#+id/radioView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:measureWithLargestChild="true"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left">
<RadioButton
android:id="#+id/radioViewSingle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:drawableRight="#android:drawable/ic_menu_search" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left">
<RadioButton
android:id="#+id/radioView2by2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="25dp"
android:drawableRight="#android:drawable/ic_menu_camera" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left">
<RadioButton
android:id="#+id/radioView3by3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="#android:drawable/ic_menu_always_landscape_portrait" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left">
<RadioButton
android:id="#+id/radioView4by4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="25dp"
android:drawableRight="#android:drawable/ic_menu_call" />
</LinearLayout>
</RadioGroup>
</LinearLayout>
You can put each RadioButton to one layout and give all layout_width="0dp" and give layout_weight="1" as showen below:
<RadioGroup
android:id="#+id/radioView"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:measureWithLargestChild="true"
android:orientation="horizontal">
<LinearLayout
android:gravity="left"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="0dp">
<RadioButton
android:checked="true"
android:drawableRight="#drawable/single"
android:id="#+id/radioViewSingle"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</LinearLayout>
<LinearLayout
android:gravity="left"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="0dp">
<RadioButton
android:drawableRight="#drawable/view2x2"
android:id="#+id/radioView2by2"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</LinearLayout>
<LinearLayout
android:gravity="left"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="0dp">
<RadioButton
android:drawableRight="#drawable/view3x3"
android:id="#+id/radioView3by3"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</LinearLayout>
<LinearLayout
android:gravity="left"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="0dp">
<RadioButton
android:drawableRight="#drawable/view4x4"
android:id="#+id/radioView4by4"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</LinearLayout>
</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

aligning radio buttons in android

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.

Great distribution of horizontal radio buttons

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>

Categories

Resources