问题
I'm trying to follow this example:
Link to example
He makes Fullscreen Image Slider with Swipe and Pinch Zoom Gestures. The problem is that the example includes pictures of the SDCard and want to collect pictures of the Assets folder. Could someone tell me I should change in the Utils class example to get it?
many thanks
public ArrayList<String> getFilePaths() {
Log.e("", "paso");
ArrayList<String> filePaths = new ArrayList<String>();
File directory = new File(
android.os.Environment.getExternalStorageDirectory()
+ File.separator + AppConstant.PHOTO_ALBUM);
if (directory.isDirectory()) {
File[] listFiles = directory.listFiles();
if (listFiles.length > 0) {
for (int i = 0; i < listFiles.length; i++) {
String filePath = listFiles[i].getAbsolutePath();
if (IsSupportedFile(filePath)) {
filePaths.add(filePath);
}
}
}
}
return filePaths;
}
回答1:
You can get images from assets folder this way.
try
{
AssetManager am = getAssets();
String list[] = am.list("");
int files = yourimagelist.length;
for(int i= 0;i<=files ; i++)
{
BufferedInputStream buf = new BufferedInputStream(am.open(list[positionHere]));
Bitmap bitmap = BitmapFactory.decodeStream(buf);
imageView.setImageBitmap(bitmap);
buf.close();
}
}
catch (IOException e)
{
e.printStackTrace();
}
来源:https://stackoverflow.com/questions/21453409/android-fullscreen-image-slider-with-swipe-and-pinch-zoom-gestures