/**
* 文件夹下图片的真实路径
*/
private String scanpath;
/**
* 所有图片的名字
*/
public String[] allFiles;
/**
* 想要查找的文件夹
*/
private File folder;
private List<ImageView> mItems = new Arraylist<>();
private void initDatafoot() {
folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath().toString() + "/Draw/ActivityPage");
/**将文件夹下所有文件名存入数组*/
allFiles = folder.list();
if (allFiles.length == 0 ) {//图片
Toast.makeText(DiscountActivity.this, "暂无图片", Toast.LENGTH_LONG).show();
} else {
/**遍历数组*/
for (int i = 0; i < allFiles.length; i++) {
scanpath = folder + "/" + allFiles[i];
Log.i(TAG, "initData: " + scanpath);
/**将文件转为bitmap如果为空则不是图片文件*/
Bitmap bitmap = BitmapFactory.decodeFile(scanpath);
/** 图片写入适配器*/
ImageView view = new ImageView(this);
view.setImageBitmap(bitmap);
view.setScaleType(ImageView.ScaleType.CENTER_CROP);
mItems.add(view);
}
}
}
网友评论