How to adjust space between radio button in android - 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>

Related

Make the radio button icon to center

I have 3 RadioButton like below
The . text is getting the centre, not the icon. I need both the icon and text to center
<?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">
<RadioGroup
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content" >
<RadioButton
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="Test1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:layout_gravity="center"
android:layout_weight="1"
android:text="Test2"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:layout_gravity="center"
android:layout_weight="1"
android:text="Test3"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RadioGroup>
You can try below code
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:text="Test1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:text="Test2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:text="Test3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RadioGroup>

How Can I edit my buttons

I tried to use a LinearLayout with 4 buttons but the last one was cut. How can I edit my code to get button's width corresponding to all smartphones'resolutions
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:id="#+id/red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RED" />
<Button
android:id="#+id/blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BLUE" />
<Button
android:id="#+id/yellow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YELLOW" />
<Button
android:id="#+id/green"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GREEN" />
</LinearLayout>
Thanks
make width="0dp" in all buttons and add
android:layout_weight="1"
to all buttons
First,set android:weightSum="4" in the LinearLayout.
And set android:layout_width="Odp" and android:layout_weight="1" in your Button .
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="4"
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:id="#+id/red"
android:layout_width="Odp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="RED" />
<Button
android:id="#+id/blue"
android:layout_width="Odp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="BLUE" />
<Button
android:id="#+id/yellow"
android:layout_width="Odp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="YELLOW" />
<Button
android:id="#+id/green"
android:layout_width="Odp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="GREEN" />
</LinearLayout>
</LinearLayout>
Use weightSum to get this equally divided layout by adjusting layout_weight
Try this once:
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="4"
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:id="#+id/red"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="RED" />
<Button
android:id="#+id/blue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="BLUE" />
<Button
android:id="#+id/yellow"
android:layout_width=match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="YELLOW" />
<Button
android:id="#+id/green"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="GREEN" />
</LinearLayout>
</LinearLayout>

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 allow only one radiobtton to be executed in a radiogroup inside a linear layout?

I am trying to place a radio group with 3 radio buttons inside a linear layout. My aim is to choose only one RadioButton inside the RadioGroup but, it is giving me an error that there are multiple root tags. Can someone figure out how to solve this?
file.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ok"
android:id="#+id/textemail"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
<RadioButton
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
/>
<RadioButton
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three" />
</RadioGroup>
<TextView
android:id="#+id/textView1"
android:layout_below="#+id/textemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To:"
/>
<TextView
android:id="#+id/TextTo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="khushi"/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comment:"
/>
<TextView
android:id="#+id/TextS3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="your comment"
/>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="email us "
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:inputType="textMultiLine"
android:lines="10" />
<Button
android:id="#+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Send"
android:textStyle="italic"/>
</LinearLayout>
You immediately close your radiogroup:
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"/>
This should be:
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"> // Note that there is no forward slash at the end
And you are not closing the RadioGroup:
</RadioButton> <-- This should be </RadioGroup>
Your RadioButton (views) should be children of the RadioGroup(view). By closing your RadioGroup using /> you declare the RadioButton(s) and the RadioGroup as children of the LinearLayout.
The Following should work.
<?xml version="1.0" encoding="utf-8"?>
<Linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello"
android:id="#+id/textview"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
<RadioButton
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
/>
<RadioButton
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three" />
</RadioButton>
</RadioGroup>
<TextView
android:id="#+id/textViewllol"
android:layout_below="#+id/textemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hi:"
/>
<TextView
android:id="#+id/Texme"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="comment:"
/>
<TextView
android:id="#+id/Text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="your comments"
/>
<TextView
android:id="#+id/textView45"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ok"
/>
<EditText
android:id="#+id/editTextMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:lines="10" />
<Button
android:id="#+id/button4785"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="send"
/>
</LinearLayout>
Change below -
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"/>
to
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
<RadioButton
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
/>
<RadioButton
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three" />
</RadioGroup>
One of your Text is not in correct format change it as below -
<TextView
android:id="#+id/textView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ok:"
/>
to
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ok:"
/>
One more error -
change below -
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
to
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
You have one </Radiobutton> tag above </Radiogroup> that shouldn't be here. Just remove it to have :
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
<RadioButton
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
/>
<RadioButton
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three" />
</RadioGroup>

Align multiline text in Radio group android

I am working on a quiz application, in this application i have to show 4 radio buttons with some multi-line text just like in snapshot. For this i have used radio-group, but the problem is that radio buttons are not aligned with the text properly as shown in snapshot. It becomes hosh-pash. Please somebody provide some suggestions. Thanks in advance
here is my layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/txtQ"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/screen"
android:orientation="vertical"
tools:context=".MainActivity" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textQno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1" />
<TextView
android:id="#+id/textRem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:gravity="right"
android:text="1" />
</LinearLayout>
<TextView
android:id="#+id/textQuis"
android:layout_width="fill_parent"
android:layout_height="144dp"
android:text="TextView" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/rbQ1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RadioButton
android:id="#+id/rbQ2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RadioButton
android:id="#+id/rbQ3"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RadioButton
android:id="#+id/rbQ4"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RadioGroup>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="fill" >
<Button
android:id="#+id/bMainPre"
style="#style/ButtonText"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_blue"
android:text="#string/bPrev" />
<Button
android:id="#+id/bMainNext"
style="#style/ButtonText"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_blue"
android:text="#string/bNext" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill" >
<Button
android:id="#+id/bshowAnswer"
style="#style/ButtonText"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_blue"
android:text="#string/bShow" />
<Button
android:id="#+id/bSubAns"
style="#style/ButtonText"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_blue"
android:text="#string/bsumit" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Do this to add aligned text to a radiobutton:
<RadioButton
android:id="#+id/rbQ1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="YOUR TEXT HERE"
android:gravity="center"
android:layout_gravity="center"
android:layout_margin="5dip" />

Categories

Resources