繁体   English   中英

为API 8中的RadioButtons复制android:drawableStart

[英]Copying android:drawableStart for RadioButtons in API 8

我需要一个自定义单选按钮,该按钮具有自定义背景,居中文本,紧邻该文本的图标,但没有默认指示器。

目前,我有以下代码:

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

问题是在drawableLeft定义的图标一直推到最左边,即

[icon]____Lorem ipsum…________

我需要这个:

____[icon]Lorem ipsum…________

当我使用android:button="@drawable/icon ,会发生同样的事情;图标位于View的最左侧,然后将文本居中于剩余空间内(而不是相对于整个View )。我使用的是Android API 8,因此无法使用drawableStart ,因此我需要一种方法来复制其行为(至少我认为是这样做的)。文本是动态的,并且在运行时更改,因此我无法对填充进行硬编码。

我的问题与这个问题非常相似,但是那个人只需要一个Button ,但是我需要一个在RadioGroup工作的RadioButton

首先想到的是尝试

android:paddingLeft="#db"

其中“ #db”是将所有内容居中所需的像素数


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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM