Android 长可绘制列表
Android long drawable list
我在 android Java 文件中有这个列表:
int[] imagelist = new int[]{R.drawable.n0d,R.drawable.n1d,R.drawable.n2d};
如何使用循环使这个列表更长?最后我想要这样的东西:
int[] imagelist = new int[]{R.drawable.n0d,R.drawable.n1d,...,R.drawable.n85d};
稍后我想在 for 循环中使用它,以在 ImageViews 中显示图像:
int lenght = 3; //I'd like it to be: int lenght = 85;
for (int i=0;i<lenght;i++){
imageViews[i] = new ImageView(this);
imageViews[i].setImageResource(imagelist[i]);
imageViews[i].setLayoutParams(LayoutParamsview);
linearlayout.addView(imageViews[i]);
}
我找到了答案..!
我使用了 getIdentifier.
for (int i=0;i<lenght;i++){
imagelist[i] = getResources().getIdentifier("n"+(i)+"d","drawable",getPackageName());
}
我在 android Java 文件中有这个列表:
int[] imagelist = new int[]{R.drawable.n0d,R.drawable.n1d,R.drawable.n2d};
如何使用循环使这个列表更长?最后我想要这样的东西:
int[] imagelist = new int[]{R.drawable.n0d,R.drawable.n1d,...,R.drawable.n85d};
稍后我想在 for 循环中使用它,以在 ImageViews 中显示图像:
int lenght = 3; //I'd like it to be: int lenght = 85;
for (int i=0;i<lenght;i++){
imageViews[i] = new ImageView(this);
imageViews[i].setImageResource(imagelist[i]);
imageViews[i].setLayoutParams(LayoutParamsview);
linearlayout.addView(imageViews[i]);
}
我找到了答案..! 我使用了 getIdentifier.
for (int i=0;i<lenght;i++){
imagelist[i] = getResources().getIdentifier("n"+(i)+"d","drawable",getPackageName());
}