在我的应用程序中....有一些图像,例如 temp1.jpg、temp2.jpg .....upto temp35.jpg,
所以在单击按钮时,我想在 ImageView 中加载一张一张的图像.... 我想这样做:
cnt=1;
imagename="temp" + cnt + ".jpg";
cnt++;
所以我的困惑是“无论如何都可以从 temp1.jpg 等字符串(图像名称变量)在 imageview 中加载图像。”
最佳答案
你可以试试这个:
int cnt = 1;
//Bitmap bitmap = BitmapFactory.decodeFile("temp" + cnt + ".jpg");
int imageResource = getResources().getIdentifier("drawable/temp" + cnt + ".jpg", null, getPackageName());
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), imageResource);
imageView.setImageBitmap(bitmap);
cnt++;
希望这就是您要找的。p>
关于android - 在 Android 的 ImageView 中加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3193356/