【发布时间】:2018-06-07 00:27:17
【问题描述】:
drawable foder 中有很多图像,因此我想手动创建所有图像资源 id 的数组,我想动态获取数组中可绘制文件夹的所有图像。 目前我正在使用此代码:
for(int i=1;i<=9;i++)
{
int imageKey = getResources().getIdentifier("img"+i, "drawable", getPackageName());
ImageView image = new ImageView(this);
image.setId(imgId);
image.setImageResource(imageKey);
image.setScaleType(ImageView.ScaleType.FIT_XY);
viewFlipper.addView(image, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
imgId++;
}
但在该代码中,我需要手动编辑图像名称以获取资源 ID,但我想获取具有任何名称的所有图像..
【问题讨论】:
标签: android