Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put an image to the right of a radio button, Android

I am trying to make a radio button list of 4 items. Each item needs to have text to it's right, but also an image to the right of the text. The image is not the radio button itself, it's an image describing the option. I have no luck so far, the designer seems to be useless to put things in place. You have to know how to code this in XML. My XML looks like this:

<?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:weightSum="1" android:baselineAligned="true" android:orientation="horizontal">
    <RadioGroup android:layout_weight="0.50" android:layout_height="wrap_content" android:id="@+id/radioGroup1" android:layout_width="0dp">
        <RadioButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:checked="true" android:text="A" android:id="@+id/radio0"></RadioButton>
        <ImageView android:layout_toRightOf="@id/radio0" android:layout_height="wrap_content" android:src="@drawable/A2" android:layout_width="wrap_content" android:id="@+id/imageView1"></ImageView>
        <RadioButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="B" android:id="@+id/radio1"></RadioButton>
        <RadioButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="C" android:id="@+id/radio2"></RadioButton>
        <RadioButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="D" android:id="@+id/radio3"></RadioButton>
    </RadioGroup>

</LinearLayout>

Here I am trying to put one image to the right of the first radio button, with no success. How do I put images to the right of the radio buttons?

like image 758
user1097185 Avatar asked Jan 25 '12 14:01

user1097185


People also ask

Is it possible to add an image on the radio button control?

To use a custom image in a radio button control or a checkbox control, ensure the Add display image check box is selected. If you right-click on the Display field, this will open a prompt allowing the user to select an image on either the Reporting Server or WebFOCUS Client. The formats allowed are .

Can we add an image to a button in android?

In android, we can add an image to the button by using <ImageButton> attribute android:src in XML layout file or by using the setImageResource() method. In android, we can create ImageButton control in two ways either in the XML layout file or create it in the Activity file programmatically.

How to set radio button in android?

Open “res/layout/main. xml” file, add “RadioGroup“, “RadioButton” and a button, inside the LinearLayout . Radio button selected by default. To make a radio button is selected by default, put android:checked="true" within the RadioButton element.

What are the methods of radio button in android?

RadioButton is a two states button which is either checked or unchecked. If a single radio button is unchecked, we can click it to make checked radio button. Once a radio button is checked, it cannot be marked as unchecked by user.


2 Answers

For a button you can put drawables to the Top/right/left/bottom of it. So I thought it might work the same way for radiobutton.

Have a look at this link in the android developers site

Did you try this?

Update

So in your case, remove the imageview and add android:drawableRight (or left/bottom/top) in your radiobuttons

<RadioButton
    android:drawableRight="@drawable/A2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:checked="true"
    android:text="A"
    android:id="@+id/radio0"/>
like image 150
Orkun Ozen Avatar answered Sep 16 '22 19:09

Orkun Ozen


<RadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/ic_launcher"/>

RadioButton itself contains a TextView as default.. so you can do all the operations those are present for any TextView.

BONUS: If you want to change the circular dot that shows check status, just update the android:button tag to refer your own drawable.

like image 23
Gautam Kumar Avatar answered Sep 17 '22 19:09

Gautam Kumar