如何以编程方式将图像设置为RadioButton参数?(How to set an image as a RadioButton argument programmatically?)

编程入门 行业动态 更新时间:2024-10-24 10:22:44
如何以编程方式将图像设置为RadioButton参数?(How to set an image as a RadioButton argument programmatically?)

我有一个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.

更多推荐

本文发布于:2023-07-08 19:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1080215.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:设置为   图像   参数   方式   argument

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!