android怎样浏览一个文件夹里的图片呢?要读到drawable里吗,还是可以直接浏览?最好能一部分一部分缓冲着读,希望大家指点一下
------解决方案--------------------
遍历文件夹调用BitmapFactory.decodeFile(String pathName)读呀~
------解决方案--------------------
用Gallery组件去显示
------解决方案--------------------
嗯,我有个异步加载图片的,你看看吧。
/**
* Method name: showPapers<BR>
* Method description: 异步加载墙纸<BR>
*
* @param adapter
* @param wallpaper
*/
private void showPapers(WallPaperAdapter adapter,ArrayList<PathName> list, String wallpaper){
ImageLoadTask task = new ImageLoadTask(list, adapter, 5);
task.execute(wallpaper);
}
package com.jftt.smart.activity.task;
import java.util.ArrayList;
import com.jftt.smart.activity.adapter.WallPaperAdapter;
import com.jftt.smart.pojo.PathName;
import com.jftt.smart.util.SceneUtil;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
public class ImageLoadTask extends AsyncTask<String, PathName, Void>{
private static final String TAG = ImageLoadTask.class.getSimpleName();
private WallPaperAdapter adapter;
private ArrayList<PathName> list;
private int index;
public ImageLoadTask(ArrayList<PathName> list, WallPaperAdapter adapter, int index){
Log.i(TAG, "ImageLoadTask()");
this.list = list;
this.adapter = adapter;
this.index = index;
}
@Override
protected void onPreExecute() {
Log.i(TAG, "onPreExecute()");
}
@Override
protected Void doInBackground(String... papers) {
Log.i(TAG, "doInBackground()");
String selectedpaper = papers[0];
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 16;
for(int i = index; i< list.size(); i++){
PathName bean = list.get(i);
bean.image = SceneUtil.decodeBitmap(bean.path, options);
if(selectedpaper!=null && selectedpaper.equals(bean.path)){
bean.checked = true;
}
publishProgress(bean);
}
return null;
}
@Override
public void onProgressUpdate(PathName... beans) {
Log.i(TAG, "onProgressUpdate()");
if(isCancelled()) {
return;
}
PathName bean = beans[0];
adapter.add(bean);
adapter.notifyDataSetChanged();
}
@Override
protected void onPostExecute(Void result) {
Log.i(TAG, "onPostExecute()");
}
}