我想创建一个包含多个图像的数组。稍后,我必须在我的代码循环中使用该数组。任何人都可以建议,如果我可以创建一个图像数组。如何创建图像数组?
-1
A
回答
0
限定图片ID这样
int[] p = {R.drawable.image1, R.drawable.image2....}
现在
该阵列的不同条件使用部件阵列等
yourbutton.setBackgroundResource(p[0]) // or p[1]
或者可以使用ENUM,使其更具有可读性..
0
这会解决你的问题:
int imageArray[] = new int[number_of_images];
for (int i = 0; i < numImages; i++)
imageArray[i] = getDrawableId(getApplicationContext(),"R.drawable." + image_names[i]);
0
您可以定义图像文件名的数组:
String fileNames[] = {"temp.jpg", "sample_img28.jpg", "normImg.jpg", "drawing.png", "film.png"};
,并添加那些MeidaTracker当初始化应用
MediaTracker tracker = null;
public void init() {
tracker = new MediaTracker(this);
for(int i = 0; i < fileNames.length; i++) {
System.out.println(" path :"+this.getCodeBase());
image[i] = getImage(this.getCodeBase(),fileNames[i]);
image[i] = image[i].getScaledInstance(256, 256, Image.SCALE_SMOOTH);
tracker.addImage(image[i], i);
}
try {
tracker.waitForAll();
}
}
0
创建自己的customImageAdapter延伸ArrayAdapter。
arrayAdapter的示例代码:
public class CustomImageAdapter extends BaseAdapter{
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
public CustomImageAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
// if you want to display the image modify the content according o your need
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_row, null);
ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image);//thumb image
return vi;
}
相关问题
- 1. 如何创建一个图像数组?
- 2. 创建Numpy数组图像
- 3. 如何从数组中的图像源创建画布图像?
- 4. 如何从swift中的字节数组创建位图图像
- 5. 如何创建像素值数组?
- 6. 如何使用一组图像创建全景图像
- 7. JavaFx - 从图像数组创建动画
- 8. 创建收集图像数组
- 9. 从图像创建一个数组
- 10. 创建一个图像对象数组
- 11. 从数组创建图像文件
- 12. 如何创建图像CvSeq
- 13. 如何创建的图像
- 14. 如何从目录中的图像创建多维数组?
- 15. 如何从Android中的图像数组创建视频?
- 16. 如何创建一个图像URL数组
- 17. 如何使用opencv从数组创建二进制图像?
- 18. 如何使用jquery创建我的图像数组?
- 19. 如何使用2d rgb数组在C++中创建图像?
- 20. 如何从数组中创建图形?
- 21. 如何从数组创建对象图
- 22. 如何创建一个tabView像图像
- 23. 如何从非图像数据创建灰度图像
- 24. 如何创建创建关联数组?
- 25. 如何创建“图像建设”效果
- 26. 如何创建一个由多个图像组成的位图?
- 27. 如何从图形创建图像?
- 28. iOS - 如何为图像创建图层
- 29. 如何在图像上创建图层?
- 30. 如何使用图像视图从图像数组中创建随机图像生成器?
你试过了什么?首先粘贴一些代码 –