Android: Fullscreen Image Slider with Swipe and Pinch Zoom Gestures

非 Y 不嫁゛ 提交于 2019-12-10 23:46:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!