在android中,是否可以将单选按钮的drawableLeft图像放在图标的最左边?

在android中,是否可以将单选按钮的drawableLeft图像放在图标的最左边?,android,radio-button,android-drawable,radio-group,Android,Radio Button,Android Drawable,Radio Group,通过这个链接,我可以显示带有图像和文本的单选按钮 如果使用drawableLeft,则可绘制图像位于收音机图标圆形图标和文本之间,以显示是否选中 但我想要的是,首先在最左边显示可绘制的图像,然后在可绘制中显示带有空格/填充的收音机图标,然后在右边显示文本 我可以在下面显示,但我希望拖拉机图像位于圆形图标的左侧 我的代码如下:` <RadioGroup android:id="@+id/radio_group_machine_type"

通过这个链接,我可以显示带有图像和文本的单选按钮

如果使用drawableLeft,则可绘制图像位于收音机图标圆形图标和文本之间,以显示是否选中

但我想要的是,首先在最左边显示可绘制的图像,然后在可绘制中显示带有空格/填充的收音机图标,然后在右边显示文本

我可以在下面显示,但我希望拖拉机图像位于圆形图标的左侧

我的代码如下:`

        <RadioGroup
            android:id="@+id/radio_group_machine_type"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <RadioButton
                android:id="@+id/radio_btn_tractor"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:paddingLeft="10dp"
                android:drawableLeft="@drawable/tractor_icon"

                android:text="@string/tractor_label" />

            <View
                style="@style/Divider"
                android:layout_height="1dp"
                android:background="@color/black_tint_40" />

            <RadioButton
                android:id="@+id/radio_btn_combine"
                android:layout_width="match_parent"
                android:drawableRight="@drawable/car_icon"
                android:layout_height="50dp"
                android:text="@string/combine_label" />
        </RadioGroup>

    </LinearLayout>`
我尝试使用在RadioButton左侧拍摄ImageView,但问题是单击ImageView时没有选择单选按钮


那么有可能吗?

您可以尝试以下解决方案:

<RadioGroup
            android:id="@+id/radio_group_machine_type"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:src="@drawable/tractor_icon"/>
                <RadioButton
                    android:id="@+id/radio_btn_tractor"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:paddingLeft="10dp"
                    android:text="@string/tractor_label" />
            </LinearLayout>

            <View
                style="@style/Divider"
                android:layout_height="1dp"
                android:background="@color/black_tint_40" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:src="@drawable/car_icon"/>
                <RadioButton
                    android:id="@+id/radio_btn_combine"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:text="@string/combine_label" />
            </LinearLayout>
        </RadioGroup>

根据您的要求调整高度和宽度

android:drawableLeft您是否尝试过此功能?我想您必须尝试自定义单选按钮,无论您想要什么,都可以使用此单选按钮…..请参见此Github示例@Ervisalsenjaliya感谢链接我尝试过此功能,但单击ImageView时未选择单选按钮,所以行的这部分看起来没有响应。是否可以将imageview的click事件传递给radiobutton的selected事件?然后为on clicklistener编写代码,并将选择设置为该单选项。@ShirishHerwade将click listener添加到为每个radiobutton提供的LinerLayout,选择单选按钮的状态并将其切换。@RahulAhuja是的,如果我不想创建CustomExtendedRadionButton,我还认为我必须去解决这个问题:。。。。。。感谢bothNitin Patel也感谢您使用If..Else语句。假设用户单击该图像视图,则选中特定的radiobutton ID。并使用SharedReference获取radiobutton的状态
    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.so.gradledemo.MainActivity">

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@android:drawable/ic_menu_camera" />

            <RadioButton
                android:id="@+id/radio0"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="camera" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@android:drawable/alert_dark_frame" />

            <RadioButton
                android:id="@+id/radio01"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true" 
                android:text="frame" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@android:drawable/arrow_down_float" />

            <RadioButton
                android:id="@+id/radio02"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="arrow"/>

        </LinearLayout>

    </RadioGroup>

</LinearLayout>