Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android how to do image screen slide?

I'm building a very basic gallery on android, it shows the last image on the camera folder and the user can slide left to see the previous one.

I finished an implementation using a viewpager, and a pagerAdapter using sampleSize to scale images. My problem is that the implementation is nowhere as efficient as the default gallery app, every time you slide an image you have to wait around 200ms for the next one to load. So basically my idea on how to implement it is not working out.

How can I do this efficiently, and if possible with an implementation that allows zooming in and out later on?


This looks promising but I don't know how to implement it with files instead of drawables http://www.androidviews.net/2012/11/photoview/


EDIT:

I've managed to improve speed a bit using photoview (a hacked viewpager), however it takes too much to convert the filepaths to bitmaps or drawables.

I have tried these two methods suggested by dilix and iDroid Explorer:

// Method A
Drawable d = Drawable.createFromPath(imagePath);
imageView.setImageDrawable(d);

// Method B
Bitmap myBitmap = BitmapFactory.decodeFile(imagePath);
imageView.setImageBitmap(myBitmap);

But both produce error Bitmap too large to be uploaded into a texture. I need to get the image to the imageView as fast as possible and somehow bypass this error and maybe I'll get a decent speed. Right now I'm scaling the images and converting them to a drawable but it's not very efficient.

like image 495
lisovaccaro Avatar asked Jan 21 '13 21:01

lisovaccaro


3 Answers

Check this awesome website : http://www.androidviews.net/ and maybe this is what you want: http://www.androidviews.net/2012/11/photoview/

It has page scroll, zooming and panning as you need I have used it in my project with some modifications and lazy image loading. It is working exactly as you need.

like image 91
Naveen Avatar answered Nov 20 '22 15:11

Naveen


See the official documentation for a great example that will walk you through using bitmaps with a viewpager efficiently. You should use a cache of the images that have already been loaded, and the images should be loaded outside of the UI thread. You also want to scale the image to the minimum size needed for your display (usually powers of two - note that the image won't always scale to what you ask it to!) ViewPager also loads images in the background to prepare for the next slide, which is set with the setOffScreenPageLimit method (the default is usually good, I think it's 2.)

https://developer.android.com/training/displaying-bitmaps/index.html

like image 1
ndw Avatar answered Nov 20 '22 16:11

ndw


I am not sure whether you got correct solution or not. But if you want to continue with your own implementation with your given link then:

http://www.androidviews.net/2012/11/photoview/   //this link is given in your question

And you can see this SO for how to convert file's path in to the drawable. Now, you get drawable of your specified file and implement on the link you have given.

I think that link will works nice.

Feel free to comments.

like image 1
Shreyash Mahajan Avatar answered Nov 20 '22 16:11

Shreyash Mahajan