0
嘿,你好吗?我为我的应用程序设置了一个图库视图,我想从我的SD卡上的特定图像文件夹中加载此视图中的图像。有人可以帮助我,因为我搜索了很多,没有提供的解决方案工作。Android,将特定文件夹中的图像加载到图库视图
我已经成功地将RES/DRAWABLE文件夹中的图像加载到我的图库视图中,但从未成功完成原始计划。
这是imageadapter类别I其中i从RES加载图像/文件夹绘制
public class ImageAdapter extends BaseAdapter
{
public ImageAdapter(Context c)
{
mContext = c;
}
public int getCount()
{
return mThumbIds.length;
}
public Object getItem(int position)
{
return position;
}
public long getItemId(int position)
{
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
ImageView imageView;
if (convertView == null)
{
imageView = new ImageView(mContext);
imageView.setLayoutParams(new Gallery.LayoutParams(100, 100));
imageView.setAdjustViewBounds(false);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(18, 18, 18, 18);
}
else
{
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
private Context mContext;
private Integer[] mThumbIds =
{
R.drawable.image_1,
R.drawable.image_2,
R.drawable.image_3,
R.drawable.image_4
};
}
heyy谢谢,我刚刚来到这里说我设法解决它,看起来就像这个指南讨论它的方式几乎一样...我使用了fileinputstream和bufferedinputstream,我得到了目录中所有文件的列表,读入fileinputstream并将其放入缓冲区,然后创建一个位图并将其添加到位图的数组列表中。谢谢 – aminet91 2011-03-26 21:42:41
现在好了我有一个新的问题,我不能加载超过500kb的图像,任何解决方案?我的应用程序崩溃 – aminet91 2011-03-26 21:52:12
最有可能 - 你有OutOfMemoryError。没有为应用程序提供如此巨大的内存量,Bitmaps也不会自动释放 - 您应该使用Bitmap.recycle()手动删除它们。您应该根据其可见性为位图添加加载/卸载功能。 – OleGG 2012-02-11 17:22:25