Can i have a Linear layout inside RadioGroup to hold radio button? - android

I want to have a Customized Radio Group view. So i have created xml view as below
<RadioGroup
android:id="#+id/selectUserRadioBtnContainer"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingRight="30dp"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:textSize="14sp"
android:fontFamily="normal"
android:layout_gravity="left|center_vertical"
android:text="#string/btnTextAddPic"
android:cropToPadding="true"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:textColor="#ffffff"
android:background="#drawable/profile_pic_rounded_background" />
<TextView
android:id="#+id/txtUserFullName"
style="#style/reviewInputLabels"
android:layout_width="0dip"
android:layout_height="30dp"
android:textColor="#33B5E5"
android:gravity="center_vertical|left"
android:textSize="16sp"
android:layout_weight="1"
android:text="Patient Name"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:tag="MAINUSER"
style="#style/radLabel"
android:button="#drawable/button_radion_default_custom" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingRight="30dp"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:textSize="14sp"
android:fontFamily="normal"
android:layout_gravity="left|center_vertical"
android:text="#string/btnTextAddPic"
android:cropToPadding="true"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:textColor="#ffffff"
android:background="#drawable/profile_pic_rounded_background" />
<TextView
android:id="#+id/txtUserFullName"
style="#style/reviewInputLabels"
android:layout_width="0dip"
android:layout_height="30dp"
android:textColor="#33B5E5"
android:gravity="center_vertical|left"
android:textSize="16sp"
android:layout_weight="1"
android:text="Patient Name"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:tag="MAINUSER"
style="#style/radLabel"
android:button="#drawable/button_radion_default_custom" />
</LinearLayout>
</RadioGroup>
Is this a right way to do?. The problem that I am facing is Radio buttons are not considered as children of Radio Group. Can anybody help me out with this ?

Try this for placing text and image on left of radio button
<RadioButton
android:id="#+id/rbtnid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="#color/white"
android:button="#null"
android:drawablePadding="30dp"
android:drawableRight="#android:drawable/btn_radio"
android:text="rtext"
android:gravity="center|right"/>
Hope it helps.

Related

Radio group in table layout with radio buttons aligned to columns

I am developing a feedback application which should has similar layout to this screen. [1]: https://i.stack.imgur.com/xn3kh.jpg
I have designed the xml for layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.zankrutparmar.feedback.Frag_one">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/frag_one_title"
android:textColor="#fff"
android:textStyle="bold|italic"
android:textSize="35dp"
android:textAlignment="center"/>
<LinearLayout
android:layout_width="819dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:layout_marginEnd="#dimen/activity_vertical_margin"
android:text="Poor"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="35dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_vertical_margin"
android:text="Average"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="35dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_vertical_margin"
android:text="Good"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="35dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_vertical_margin"
android:text="Very Good"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="35dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_vertical_margin"
android:text="Excellent"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="35dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="6">
<TextView
android:layout_width="58dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_vertical_margin"
android:layout_weight="1"
android:text="Theme & Decor"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="25dp"
android:textStyle="bold|italic" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_vertical_margin"
android:layout_weight="5"
android:orientation="horizontal">
<RadioButton
android:id="#+id/poor1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/custom_btn_radio_poor"
android:button="#null" />
<RadioButton
android:id="#+id/average1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/custom_btn_radio_average"
android:button="#null" />
<RadioButton
android:id="#+id/good1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/custom_btn_radio_good"
android:button="#null" />
<RadioButton
android:id="#+id/very1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/custom_btn_radio_very_good"
android:button="#null" />
<RadioButton
android:id="#+id/excellent1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/custom_btn_radio_excellent"
android:button="#null" />
</RadioGroup>
</LinearLayout>
Now whenever I want to apply margin to these radio buttons the center one remains in center and pushes all other buttons far.
I also tried the answers on this question [1]: TableLayout of radiogroup(s) with respective label(s) aligned in android
But in that layout the problem is all buttons in single row are getting selected. It means Radiogroup can't be placed in that layout.
And I have to fetch questions from a database and place them in my application.
So in Future I will have to add rows dynamically.
Any help will be very appreciated. Thank you in advance.
Okay I designed a new layout and fixed those previous issues. I am uploading that code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#8bae3a"
tools:context="com.zankrutparmar.feedback.Frag_two">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_marginLeft="20dp"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView5"
android:layout_column="1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView10"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView9"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView6"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextView" />
</TableRow>
<TableRow
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<RadioGroup
android:layout_marginLeft="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:orientation="horizontal">
<RadioButton
style="#style/MyRadioButtonStyle"
android:gravity="center"
android:padding="8dp"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<RadioButton
style="#style/MyRadioButtonStyle"
android:gravity="center"
android:paddingLeft="8dp"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
style="#style/MyRadioButtonStyle"
android:gravity="center"
android:paddingLeft="8dp"
android:layout_marginLeft="5dp"
/>
<RadioButton
style="#style/MyRadioButtonStyle"
android:gravity="center"
android:paddingLeft="8dp"
android:layout_marginLeft="7dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</RadioGroup>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<RadioGroup
android:layout_marginLeft="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:orientation="horizontal">
<RadioButton
style="#style/MyRadioButtonStyle"
android:gravity="center"
android:padding="8dp"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<RadioButton
style="#style/MyRadioButtonStyle"
android:gravity="center"
android:paddingLeft="8dp"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
style="#style/MyRadioButtonStyle"
android:gravity="center"
android:paddingLeft="8dp"
android:layout_marginLeft="5dp"
/>
<RadioButton
style="#style/MyRadioButtonStyle"
android:gravity="center"
android:paddingLeft="8dp"
android:layout_marginLeft="7dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</RadioGroup>
</TableRow>
</TableLayout>

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.

android how to add separator in headerlayout?

I want to add separator in between button and textview in my layout header contains 2 buttons and textview how do I add separator in between them?
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="50px"
android:layout_gravity="fill_horizontal"
android:background="#color/Blue"
android:orientation="horizontal" >
<Button
android:id="#+id/Back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:background="#color/Blue"
android:textSize="20sp"
android:textColor="#color/White"
android:text=" Back"
/>
<TextView
android:id="#+id/header_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:layout_toLeftOf="#+id/Exit"
android:layout_toRightOf="#+id/Back"
android:textSize="20sp"
android:textStyle="italic"
android:typeface="serif"
android:background="#color/Blue"
android:textColor="#color/White"
android:text="Games Apps"/>
<Button
android:id="#+id/Exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textSize="20sp"
android:layout_centerVertical="true"
android:background="#color/Blue"
android:textColor="#color/White"
android:layout_marginRight="5dp"
android:text=" Exit"
/>
</RelativeLayout>
Seems that you need a vertical separator:
<TextView
android:layout_width="2dp"
android:layout_height="fill_parent"
android:layout_toLeftOf="#id/header_text"
android:layout_toRightOf="#id/Back"
android:background="#00000000"
/>
add View between your button and textview
For instance
<View
android:layout_width="2dip"
android:layout_height="fill_parent"
android:layout_toLeftOf="#id/header_text"
android:layout_toRightOf="#id/Exit"
android:padding = "5dip"
android:background="#FFFF0000"
/>
May this help you..
To add seperator you have to add a view in between the objects you want seperator..
like..
<View
android:layout_width="2dip"
android:layout_height="fill_parent"
android:layout_toLeftOf="#id/header_text"
android:layout_toRightOf="#+id/Back"
android:padding = "5dip"
android:background="#FFFF0000"
/>
and change this lines in your code..
<TextView
android:id="#+id/header_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_toLeftOf="#+id/Exit"
android:layout_toRightOf="#+id/Back"
android:textSize="20sp"
android:textStyle="italic"
android:typeface="serif"
android:background="#color/Blue"
android:textColor="#color/White"
android:text="Games Apps"/>
or you can use <TableRow> </TableRow> try to put the whole code with seperator in between the views
Try this, just workaround worked for me. You can use the same logic by implementing other Layout to instead of TableLayout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="*"
android:showDividers="middle"
android:layout_centerInParent="true"
android:background="#000000"
android:divider="#000000"
>
<TableRow>
<Button
android:id="#+id/Back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:background="#ffffff"
android:textSize="20sp"
android:text=" Back"
/>
<TextView
android:id="#+id/header_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:layout_toLeftOf="#+id/Exit"
android:layout_toRightOf="#+id/Back"
android:textSize="20sp"
android:layout_marginLeft="1dp"
android:textStyle="italic"
android:background="#ffffff"
android:typeface="serif"
android:text="Games Apps"/>
<Button
android:id="#+id/Exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textSize="20sp"
android:layout_marginLeft="1dp"
android:background="#ffffff"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:text=" Exit"
/>
</TableRow>
</TableLayout>
</RelativeLayout>
Let me know you have other difficulties use this.

xml centered textview to much to left

I try to create somekind of stroke on top of my screen which displays 4 things. An backbutton on the left, the level name in the center and scoreInfoOne and scoreInfoTwo on the right, but below each other. I use following code, but the strange thing is that the level name doesn't appear to be centered, the longer the value of scoreInfoTwo is, the more the level name is on the left. Any ideas?
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="35dp"
android:background="#25ab89"
android:orientation="horizontal"
android:weightSum="4" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/ivBackButton"
android:layout_width="18dp"
android:layout_height="18dp"
android:src="#drawable/arrow" />
</LinearLayout>
<TextView
android:id="#+id/tvScoreBoard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2"
android:gravity="center"
android:text="level"
android:textColor="#ffffff"
android:textSize="18dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical"
android:paddingRight="2dp" >
<TextView
android:id="#+id/tvScoreInfoOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="0/30"
android:textColor="#ffffff"
android:textSize="12dp" />
<TextView
android:id="#+id/tvScoreInfoTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="score:"
android:textColor="#ffffff"
android:textSize="12dp" >
</TextView>
</LinearLayout>
Your child views must set the layout_width to zero:
android:layout_width="0px"
So your layout would then look like:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="35dp"
android:background="#25ab89"
android:orientation="horizontal"
android:weightSum="4" >
<LinearLayout
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/ivBackButton"
android:layout_width="18dp"
android:layout_height="18dp"
android:src="#drawable/arrow" />
</LinearLayout>
<TextView
android:id="#+id/tvScoreBoard"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2"
android:gravity="center"
android:text="level"
android:textColor="#ffffff"
android:textSize="18dp" />
<LinearLayout
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical"
android:paddingRight="2dp" >
<TextView
android:id="#+id/tvScoreInfoOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="0/30"
android:textColor="#ffffff"
android:textSize="12dp" />
<TextView
android:id="#+id/tvScoreInfoTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="score:"
android:textColor="#ffffff"
android:textSize="12dp" >
</TextView>
</LinearLayout>
First off, you cannot use android:layout_gravity="anything" in a LinearLayout. For LinearLayouts you use the weights to define how much space you want to use. For what you are trying to do, I suggest using a RelativeLayout then you can just define where you want your TextView or other items by using android:layout_below="#+id/other_textview and there are lots of android:layout_[direction] to choose from, and you can use layout_gravity="center_horizontal" with these.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="35dp"
android:background="#25ab89">
<ImageView
android:id="#+id/ivBackButton"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/arrow" />
<TextView
android:id="#+id/tvScoreBoard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_below="#id/ivBackButton"
android:gravity="center"
android:text="level"
android:textColor="#ffffff"
android:textSize="18dp" />
<TextView
android:id="#+id/tvScoreInfoOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_below="#id/tvScoreBoard"
android:alignParentRight="true"
android:text="0/30"
android:textColor="#ffffff"
android:textSize="12dp" />
<TextView
android:id="#+id/tvScoreInfoTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_below="#id/tvScoreInfoTwo"
android:alignParentRight="true"
android:text="score:"
android:textColor="#ffffff"
android:textSize="12dp" />
</RelativeLayout>

Android: RadioButton within Nested Layout under RadioGroup falls out of Group

I'm trying to get some sensible positioning of my radiobuttons which are part of a RadioGroup. I was having trouble as my RadioGroup was sitting on top of the rest of my layout design, then I use margins to push the buttons around, the problem here is this works on one or two device layouts only. I thought I struck gold when I discovered I could define my RadioGroup then put in a RelativeLayout below which amongst other things contained one of the RadioButtons, then I repeat twice more. this gives me the layout I desire. Problem is, when I run the code, the RadioButtons act link standalone buttons :(
So two questions,
can I link these buttons back to the Group?
Is there a decent way to be able to define the layout of the RadioGroup Radiobuttons independently of the Group.
I am thinking an alternative may be independent RadioButtons and use code to enable/disable them, but that does kind of defeat the usefulness of RadioGroup.
thanks.
Here is my XML layout should you be curious.
<ScrollView android:id="#+id/scrollview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#id/HDDResultsBox"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
android:windowSoftInputMode="stateHidden"
>
<RadioGroup android:id="#+id/calcBy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_below="#id/HDDResultsBox"
>
<RelativeLayout android:id="#+id/intervalBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/backgroundbox"
android:layout_margin="5dp"
android:padding="5dp"
>
<TextView android:id="#+id/intervalHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Interval"
android:gravity="left"
android:textColor="#ffffff"
android:textStyle="bold"
android:layout_marginLeft="5dp"
/>
<TextView android:id="#+id/intervalHelpText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Interval help text"
android:gravity="left"
android:textColor="#ffffff"
android:textSize="8dp"
android:layout_toRightOf="#id/intervalHeader"
android:layout_marginLeft="10dp"
/>
<LinearLayout android:id="#+id/interval2ndBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/intervalHeader"
android:layout_marginLeft="10dp"
>
<RadioButton android:id="#+id/byInterval"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
/>
<EditText android:id="#+id/intervalValue"
android:layout_width="75dp"
android:layout_height="40dp"
android:text="50"
android:textSize="14sp"
android:gravity="center"
android:inputType="number"
android:layout_marginLeft="20dp"
/>
<Spinner android:id="#+id/intervalType"
android:layout_width="match_parent"
android:layout_height="42dp"
android:drawSelectorOnTop="false"
android:layout_marginTop="1dp"
android:layout_marginLeft="10dp"
android:layout_weight="10"
android:layout_marginRight="2dp"
/>
<SeekBar android:id="#+id/intervalSeek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="8dp"
android:layout_weight="7"
/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout android:id="#+id/recordBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/backgroundbox"
android:layout_margin="5dp"
android:padding="5dp"
>
<TextView android:id="#+id/recordHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Record Duration"
android:gravity="left"
android:textColor="#ffffff"
android:textStyle="bold"
android:layout_marginLeft="5dp"
/>
<TextView android:id="#+id/recordHelpText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Record help text"
android:gravity="left"
android:textColor="#ffffff"
android:textSize="8dp"
android:layout_toRightOf="#id/recordHeader"
android:layout_marginLeft="10dp"
/>
<LinearLayout android:id="#+id/record2ndBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/recordHeader"
android:layout_marginLeft="10dp"
>
<RadioButton android:id="#+id/byrecord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
/>
<EditText android:id="#+id/recordValue"
android:layout_width="75dp"
android:layout_height="40dp"
android:text="50"
android:textSize="14sp"
android:gravity="center"
android:inputType="number"
android:layout_marginLeft="20dp"
/>
<Spinner android:id="#+id/recordType"
android:layout_width="match_parent"
android:layout_height="42dp"
android:drawSelectorOnTop="false"
android:layout_marginTop="1dp"
android:layout_marginLeft="10dp"
android:layout_weight="10"
android:layout_marginRight="2dp"
/>
<SeekBar android:id="#+id/recordSeek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="8dp"
android:layout_weight="7"
/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout android:id="#+id/playBackBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/backgroundbox"
android:layout_margin="5dp"
android:padding="5dp"
>
<TextView android:id="#+id/playBackHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Video Length"
android:gravity="left"
android:textColor="#ffffff"
android:textStyle="bold"
android:layout_marginLeft="5dp"
/>
<TextView android:id="#+id/playBackHelpText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="playBack help text"
android:gravity="left"
android:textColor="#ffffff"
android:textSize="8dp"
android:layout_toRightOf="#id/playBackHeader"
android:layout_marginLeft="10dp"
/>
<LinearLayout android:id="#+id/playBack2ndBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/playBackHeader"
android:layout_marginLeft="10dp"
>
<RadioButton android:id="#+id/byplayBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
/>
<EditText android:id="#+id/playBackValue"
android:layout_width="75dp"
android:layout_height="40dp"
android:text="50"
android:textSize="14sp"
android:gravity="center"
android:inputType="number"
android:layout_marginLeft="20dp"
/>
<Spinner android:id="#+id/playBackType"
android:layout_width="match_parent"
android:layout_height="42dp"
android:drawSelectorOnTop="false"
android:layout_marginTop="1dp"
android:layout_marginLeft="10dp"
android:layout_weight="10"
android:layout_marginRight="2dp"
/>
<SeekBar android:id="#+id/playBackSeek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="8dp"
android:layout_weight="7"
/>
</LinearLayout>
</RelativeLayout>
</RadioGroup>
</RelativeLayout>
</ScrollView>
After looking around for a solution it looks the only way to do this is to use individual radio buttons and then programmically control there on/off states.

Categories

Resources