gpt4 book ai didi

android - 动态图片源android

转载 作者:太空狗 更新时间:2023-10-29 15:31:06 27 4
gpt4 key购买 nike

我正在尝试在我的 android 应用程序中使图像动态化。在其他帖子的帮助下,我编写了这段代码,但我无法设置图像资源。这是我的代码。

// get image whose source i want to change..
ImageView IV = (ImageView) findViewById(R.id.imageView1);

// x for 1,2,3.. hangman1.png,hangman2.png and so on image are located
// under res/drawable-mdpi
int j = getResources().getIdentifier("hangman"+x, "imageView", getPackageName());

// here i get errork, The method setImageResource(int) in the type ImageView
// is not applicable for the arguments (Drawable)
IV.setImageResource( getResources().getDrawable(j) );

最佳答案

int j = getResources().getIdentifier("hangman"+x, "drawable", getPackageName());

试试这个,如果你想得到一个可绘制的。也正如 kcoppock 所说,只需使用 j。

关于android - 动态图片源android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7827116/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com