我能不能用类似
for(int i;....)
icons[i]=.....getDrawable(R.drawable.i).getBitmap();
这种形式的?

解决方案 »

  1.   

    可以创建一个循环链表。
    请看此处:http://www.189works.com/article-5504-1.html
      

  2.   

    两种方式把
    第一种:
    比如Drawable中有一系列连续的图片,img_0.png, img_1.png, img_2.png ...
    如果要动态获取这些图片,通过"R.drawable.img_x"的ID方式指定是不行的,因为这个ID无法动态变化,即你是无法通过字符串拼接的方法来实现的。
    但可以通过下面方式获取:
    String imgname = "img_" + idx;
    int imgid = getResources().getIdentifier(imgname, "drawable", "com.ucrobotics.xxx"); 
    EditText.setBackgroundResource(imgid);
    根据传递的idx的值不同,就可以动态的获取img_x所对应名称的图片资源了。
    其中"com.ucrobotics.xxx"指的是你的package name,就是Java文件最开始一行的那个。第二种
    Bitmap bmp=BitmapFactroy.decodeFile("/sdcard/xxx.png");
    imageview.setImageBitmap(bmp);