复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58public class GalleryTestActivity extends Activity { File photos[]; private static String TAG = "GalleryTest"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); File f = new File("/sdcard/pics1"); photos = f.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { return filename.endsWith("jpg"); } }); String fileList = ""; for (File aFile : photos) { fileList += aFile.getName() + "n"; } TextView v = (TextView)findViewById(R.id.FileList); v.setText(fileList); Gallery gallery = (Gallery)findViewById(R.id.Gallery); gallery.setAdapter(new AddImgAdp(this)); } public class AddImgAdp extends BaseAdapter { int GalItemBg; private Context cont; public AddImgAdp(Context c) { cont = c; TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme); GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0); typArray.recycle(); } public int getCount() { return photos.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 imgView; if (convertView == null) imgView = new ImageView(cont); else imgView = (ImageView)convertView; Bitmap bMap = BitmapFactory.decodeFile(filename); imgView.setImageBitmap(bMap); imgView.setLayoutParams(new Gallery.LayoutParams(120, 90)); imgView.setScaleType(ImageView.ScaleType.FIT_XY); imgView.setBackgroundResource(GalItemBg); return imgView; } } }
http://wang-peng1.iteye.com/blog/835426
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51//将sd卡的图片一张张显示出来,需要先全部加载然后在显示,如果加载一张显一张比较慢 public class Pics extends Activity { private ImageView image; private String[] mFiles; private int mFilePosition = 0; private ArrayList<Bitmap> bitArray; private Bitmap b; private int i; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); image = (ImageView) findViewById(R.id.image); bitArray = new ArrayList<Bitmap>(); File images = Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); try { images.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.e("file path", images.getAbsolutePath()); File[] imagelist = images.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return ((name.endsWith(".jpg")) || (name.endsWith(".png"))); } }); mFiles = new String[imagelist.length]; Log.e("size", imagelist.length + ""); for (int i = 0; i < imagelist.length; i++) { mFiles[i] = imagelist[i].toString(); } getImageFromSDCard(); } public void getImageFromSDCard() { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 8; try { for (int j = 0; j < mFiles.length; j++) { Log.d("", mFiles[mFilePosition]); b = BitmapFactory.decodeFile(mFiles[j], null); bitArray.add(b); } } catch (Exception e) { // Log error } } }
最后
以上就是潇洒糖豆最近收集整理的关于android列出目录下的所有图片的全部内容,更多相关android列出目录下内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复