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

1

7

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 ?

Trotman answered 13/5, 2014 at 6:48 Comment(5)
This does not seem to be a very good idea :/Goodden
How can i achieve this ?Trotman
There is nothing like customize RadioGroup but what you needed to achieve can achieved by your custom click listener over Linearlayout and a boolean flag. no need to radio group.Audley
for this you have manually manage your all RadioButton rather RadioGroup.Electrochemistry
it will break radio group with radio button. You will have to manage manually if you wish to use in this way.Choric
S
5

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.

Sectional answered 13/5, 2014 at 7:4 Comment(2)
This answer really helped me. I have achieved what i want.Trotman
Glad that I could help :)Goodden

© 2022 - 2024 — McMap. All rights reserved.