如何把图像到一个单选按钮,Android的权 [英] How to put an image to the right of a radio button, Android

查看:197
本文介绍了如何把图像到一个单选按钮,Android的权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做的4项单选按钮列表。每个项目需要有文字它是正确的,而且对文本的右侧的图像。的图像不是单选按钮本身,它的描述选项的图像。
我至今没有运气,设计者似乎没用放东西的地方。你必须知道如何code此XML格式。
我的XML看起来是这样的:

I am trying to make a radio button list of 4 items. Each items need 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 seem 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>

在这里,我tryiong把一个图像到第一个单选按钮的右侧,没有成功。
我要如何将图像,单选按钮的吧?

Here I am tryiong 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?

推荐答案

对于一个按钮就可以把可绘制到顶部/左/右/它的底部。所以我想这可能工作了单选按钮以同样的方式。

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.

看一看<一个href=\"http://developer.android.com/reference/android/widget/TextView.html#attr_android:drawableRight\"相对=nofollow>在Android开发者网站此链接

您是否尝试过这个?

更新

所以你的情况,删除ImageView的,并添加的android:drawableRight (或左/底/顶)在单选按钮

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"/>

这篇关于如何把图像到一个单选按钮,Android的权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆