Is it possible to add TextView below RadioButton in RadioGroup in any other way than extending and creating my custom RadioButton?
Asked
Active
Viewed 1.0k times
3 Answers
6
Yes, its possible. See below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn1" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="sample text" />
</RadioGroup>
</LinearLayout>
Sample output:

waqaslam
- 67,549
- 16
- 165
- 178
-
The problem begins though, when I need to put TextView between two RadioButtons - it is not possible to have it under RadioGroup, because the selection will be disabled and it starts doing funky things. – Michal Apr 24 '12 at 14:18
-
Could you please show screen of text between and in the bottom? Can't make it work :( – Michal Apr 25 '12 at 09:45
-
1I mean, sure the layout works just great, but functionality loses precision - if I check third RadioButton, it does weird things... – Michal Apr 25 '12 at 09:46
-
just move the TextView between two CheckBoxes. thats what i did and it worked – waqaslam Apr 25 '12 at 09:55
0
You can remove RadioGroup from your XML and add radio buttons one by one. Look at this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/radioGroup1"
android:text="RadioButton" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/radioButton1"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:text="RadioButton" />
</RelativeLayout>

Ali Behzadian Nejad
- 8,804
- 8
- 56
- 106
-
1Yes, but then I can't work with RadioButtons like with group - which involves lot of coding with own RadioButton mechanism... – Michal Apr 24 '12 at 14:18
0
I think that you can use another tricky solution. Create a gap between two radio buttons with padding or margin and then put textView on the gap.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="78dp" >
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="RadioButton"
android:layout_marginBottom="100dp"/>
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton"
android:layout_marginBottom="100dp"/>
<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
</RadioGroup>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/radioGroup1"
android:layout_centerHorizontal="true"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_alignParentTop="true"
android:layout_marginTop="200dp"/>
</RelativeLayout>

Ali Behzadian Nejad
- 8,804
- 8
- 56
- 106
-
nope, not working, try removing center_horizontal...aligns itself with top of the screen... – Michal Apr 24 '12 at 15:05