如何动态交换图像 - 显示错误的图像
我需要动态更改 ImageView 的源。我有一大堆具有相同名称的文件,存储在 res/ 下不同的 dpi 目录(drawable-hdpi 等)中。为此,我一直在使用 ImageView 的 setImageResource() 并向其传递我在运行时创建的资源 ID 数组中的值,如下所示:
decorations = new int[]{
R.drawable.bird1,
R.drawable.flower2,
R.drawable.bird3,
..etc};
无论如何,由于某种原因,第 6 个图像被损坏为用于其他用途的替代图像,资源列表中没有一个。
到底发生了什么事?
I need to change the source of an ImageView dynamically. I have a whole bunch of them with the same names, stored in their different dpi directories (drawable-hdpi etc) under res/. For this I've been using ImageView's setImageResource() and passing it a value from an array of resource IDs I've created at runtime like so:
decorations = new int[]{
R.drawable.bird1,
R.drawable.flower2,
R.drawable.bird3,
..etc};
Anyway, for some reason, the 6th image gets corrupted into an alternative image used for other things, not one in the resources list.
What on earth is going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果我有一个损坏/不正确的图像,或者图像位于错误的目录或其他东西中。不过,奇怪的是它决定只显示目录中的下一个图像,而不是仅仅因异常或其他原因崩溃。
Turns out I had a corrupt/incorrect image or the image was in the wrong directory or something. Still, strange that it decided to just display the next image in the directory rather than just crashing with an Exception or something.