Android在Imagebutton上设置动态图片

发布于 2024-10-01 15:08:19 字数 1431 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

权谋诡计 2024-10-08 15:08:20

您可以使用 类型化数组 资源。链接末尾有一个示例,说明如何将其用于可绘制对象(图像)。

编辑:

资源可以作为原始数据访问:使用AssetManager.open(..)
然后你可以使用 BitmapFactory.decodeStream(. .) 从数据流创建位图。

You could use Typed Array resource. There is an example at the end of the link how to use it for drawables (images).

Edited:

Resources can be accessed as raw data: use AssetManager.open(..)
Then you can use BitmapFactory.decodeStream(..) to create a Bitmap from the data stream.

捶死心动 2024-10-08 15:08:20

您可以在资源文件夹中获取图像。之后遵循这个简单的代码:

try {               
                Class<drawable> res = R.drawable.class;
                if(str!=null){                                   
                Field field = res.getField(str);
                int drawableId = field.getInt(null);
                bengalidaypng.setImageResource(drawableId);              
                }
            }
            catch (Exception e) {
                      System.out.println("Image not found in drawable folder");
            } 

可以找到更详细的示例 这里

You can take the images in your resource folder. After that follow this simple code:

try {               
                Class<drawable> res = R.drawable.class;
                if(str!=null){                                   
                Field field = res.getField(str);
                int drawableId = field.getInt(null);
                bengalidaypng.setImageResource(drawableId);              
                }
            }
            catch (Exception e) {
                      System.out.println("Image not found in drawable folder");
            } 

A more detailed sample can be found here.

对你的占有欲 2024-10-08 15:08:20

您可以将图像存储到数据库中,然后 当您绑定每一行时,将图像拉入 ListView

You could store the images into a database, then pull the images into the ListView when you are binding each row.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文