0

我正在开发一个应用程序,我的一项活动是一个屏幕,它可以抓取我在 /data/ 应用程序文件夹中创建的文件夹中的所有图像。我想抓取所有照片以网格格式排列,然后当一个人点击一张时,它会将其放大到全尺寸。当然,当新图像添加到文件夹时,这个图库需要更改。

似乎这将是一些简单的事情,但我在实现这一点时遇到了一些麻烦,我一直在寻找许多不同的解决方案,其中似乎都不是正确的。

我假设这将是某种 gridview/listadapter 组合。

这个问题的最佳解决方案是什么?

编辑

我研究了这些解决方案 http://www.androidhive.info/2012/02/android-gridview-layout-tutorial/ http://developer.android.com/guide/topics/ui/layout/gridview.html#例子

但我的困惑是这样的代码

private Integer[] mThumbIds = {
        R.drawable.sample_2, R.drawable.sample_3,
        R.drawable.sample_4, R.drawable.sample_5,
        R.drawable.sample_6, R.drawable.sample_7,
        R.drawable.sample_0, R.drawable.sample_1,
        R.drawable.sample_2, R.drawable.sample_3,
        R.drawable.sample_4, R.drawable.sample_5,
        R.drawable.sample_6, R.drawable.sample_7,
        R.drawable.sample_0, R.drawable.sample_1,
        R.drawable.sample_2, R.drawable.sample_3,
        R.drawable.sample_4, R.drawable.sample_5,
        R.drawable.sample_6, R.drawable.sample_7
};

我该怎么办,因为我的应用程序文件夹中的图像数量会不断变化。以及如何首先从该文件夹中加载图像哈哈

4

1 回答 1

1

您看过Android 开发者网站中的缓存位图吗?我认为它做的事情类似于你想要的。它还提供了示例的代码。

您最好将图像存储在 sd 卡内的路径中,因为它们需要动态更改。然后要从该路径获取图像路径,请使用以下内容(假设您只有该目录中的图像):

File imagesDir = new File(Environment.getExternalStorageDirectory(), "yourpath");
for (File f : yourDir.listFiles()) {
   if (f.isFile())
      String image_path = f.getPath();
      // make something with the name
}

此外,要从 sd 中的文件加载位图,请使用以下内容:

Bitmap b = BitmapFactory.decodeFile("your_image_path");

请记住加载位图的缩小版本以提高内存效率。请参阅此处了解更多信息。

希望能帮助到你。

于 2012-07-25T12:44:00.103 回答