Android 安卓ImageView作为单选按钮

Android 安卓ImageView作为单选按钮,android,imageview,android-imageview,android-radiogroup,android-radiobutton,Android,Imageview,Android Imageview,Android Radiogroup,Android Radiobutton,我想要一些图像视图用作单选按钮。但是我不想让单选按钮的迷你按钮选择它;我希望这个小按钮消失,而ImageView是整个按钮。因此,像下面这样的解决方案是不好的 <RadioButton android:id="@+id/myId" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableRight="@drawable/myIcon"/&

我想要一些
图像视图
用作
单选按钮
。但是我不想让
单选按钮的迷你按钮选择它;我希望这个小按钮消失,而ImageView是整个按钮。因此,像下面这样的解决方案是不好的

<RadioButton
    android:id="@+id/myId"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableRight="@drawable/myIcon"/>


是否有一个小部件或什么东西我可以使用
imageview
作为
RadioButton
,或者我应该自己编程按钮的所有逻辑?

只需在RadioButton的XML声明的
android:background
中设置图像。 同时将
android:button
设置为透明:
android:button=“@android:color/transparent”


如果您想拥有不同的状态,请为这两个状态创建一个具有不同图像的选择器。

我建议您创建自定义单选按钮。检查Evan Bashir的这一点

您可以尝试使用按钮属性,如bellow

<RadioButton
android:id="@+id/myId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/myIcon"/>
您可以在通过以下xml文件选择RB时更改图像…将此文件保存在drawable文件夹中,并在
按钮中调用它,或按语法调用它

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/star_down" />
<item android:state_checked="false" android:drawable="@drawable/star" />
</selector>

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/star_down" />
<item android:state_checked="false" android:drawable="@drawable/star" />
</selector>