我有一个RadioGroup,它由五个RadioButtons组成。 我想要实现的是将图像设置为RadioButton参数。 到目前为止发现了这种方式
radio0.setBackgroundResource(<drawable ID, int>);但它给出了这样的东西(在图像编辑器中添加了描述“isSelected”):
有没有办法以编程方式设置背景属性并将图像移动到右侧? 或者可能有另一种方法在RadioButton旁边设置图像而不是将其用作背景图像?我只对编程解决方案感兴趣,因为RadioGroup在循环工作期间被清理并再次填充。
I have a RadioGroup which consists of five RadioButtons. What I'd like to achieve is setting an image as a RadioButton argument. So far found this way:
radio0.setBackgroundResource(<drawable ID, int>);but it gives something like this (descriptions "isSelected" added in an image editor):
Is there any way to programmatically set background properties and move the image to the right? Or maybe there is another way to set an image next to RadioButton instead of using it as a background image?I'm interested only in programmatical solutions, as the RadioGroup is cleared up and filled again during loop work.
最满意答案
我的一个朋友帮我解决了这个问题。
而不是在问题中发布的代码行,我现在使用这个:
radio0.setCompoundDrawablesWithIntrinsicBounds(0, 0, <drawable ID, int>, 0);第三个参数对应于android:drawableRight XML参数。 更多相关信息: 点击 。
多亏了它,一张照片设置在RadioButton的右边,最后看起来应该是这样。
A friend of mine helped me to figure out this issue.
Instead of the code line posted in the question I use this one now:
radio0.setCompoundDrawablesWithIntrinsicBounds(0, 0, <drawable ID, int>, 0);The third parameter corresponds to android:drawableRight XML parameter. More on this: click.
Thanks to it a picture is set to the right of the RadioButton and finally it looks like it should.
更多推荐
发布评论