Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 618
Chandrakanth Gowda Avatar asked May 13 '14 06:05

Chandrakanth Gowda


People also ask

Can we use linear layout in RelativeLayout inside?

We can use LinearLayout inside RelativeLayout. We can also use RelativeLayout as a Child of LinearLayout.

How do you move a button in linear layout?

You can set the android:layout_weight='1' and both buttons will share the screen equally(side by side) or if you want the extra space between them, you can place a button each in a linear layout and set the android:layout_gravity to left and right for each. Save this answer.

How do I create a horizontal radio button?

To make a horizontal radio button set, add the data-type="horizontal" to the fieldset . The framework will float the labels so they sit side-by-side on a line, hide the radio button icons and only round the left and right edges of the group.


1 Answers

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.

like image 148
MysticMagicϡ Avatar answered Sep 28 '22 03:09

MysticMagicϡ