复制android:API 8中单选按钮的drawableStart

复制android:API 8中单选按钮的drawableStart,android,android-layout,Android,Android Layout,我需要一个自定义单选按钮,带有自定义背景、居中文本、文本前的图标,但没有默认指示器 目前,我有以下代码: <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:button="@null" android:background="@drawable/bg_rbtn_c

我需要一个自定义单选按钮,带有自定义背景、居中文本、文本前的图标,但没有默认指示器

目前,我有以下代码:

<RadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:button="@null"
    android:background="@drawable/bg_rbtn_custom"
    android:drawableLeft="@drawable/icon"
    android:text="Lorem ipsum…" />
我需要这个:

____[icon]Lorem ipsum…________
当我使用
android:button=“@drawable/icon
”时也会发生同样的情况;图标位于
视图的最左侧,然后文本在剩余的空间中居中(而不是相对于整个
视图居中).我是Android API 8,所以我不能使用
drawableStart
,所以我需要一种方法来复制它的行为(至少我假设它是这样做的)。文本是动态的,将在运行时改变,所以我不能真正硬编码填充


我的问题与非常相似,但那个家伙只需要一个
按钮,但我需要一个
无线电按钮,它将在
放射组中工作

android:paddingLeft="#db"
其中“#db”是将所有物体居中所需的像素数



在尝试您的代码并将背景和图标替换为我的本地资源后,我无法重新创建您的问题。您正在使用的图标的右边缘是否可能有透明像素?

您在谈论哪个问题?
drawableStart
未显示,或者图像显示不正确文本旁边?我同时使用了drawableStart和drawableLeft,两者都导致图标出现,并且图标在文本旁边齐平。我没有成功地创建文本和图标之间的间隙,并且drawableStart没有出现问题。因此,我建议切换图标,看看是否这是图标本身的问题,或者与代码有关。我建议使用paddingLeft的原因是,如果你能将两者结合在一起,那么你可以通过将它们推向中心来“居中”,因为我相信android:gravity=“center“只会将文本居中
drawableLeft
对我有效,但唯一的问题是间距。文本是动态的,所以我不能硬编码填充。至于为什么
drawableStart
不起作用,我刚刚发现这是因为我使用的是API 8,
drawableStart
是API 14哈哈。很高兴了解drawableStart!我从来没有想到过。很抱歉,我帮不上什么忙了
android:paddingLeft="#db"