Charlie
Charlie

Reputation: 325

Android: code to zoom with ViewPager

I'm trying to get a code to zoom in images implemented with ViewPager in Universal Image Loader. I've tried these but none is what I want:

Someone knows a code to zoom in ViewPager? thanks

Upvotes: 0

Views: 2308

Answers (2)

Simon
Simon

Reputation: 11190

ScrollingViewPager.java https://gist.github.com/slightfoot/5475083

Once added to your project use that extended ViewPager in your layouts instead of the support library one. Then you can use https://github.com/MikeOrtiz/TouchImageView and just add implements ScrollingViewPager.CanScrollCompat to his TouchImageView to make it compatible and your done.

Upvotes: 3

Sergey Neskoromny
Sergey Neskoromny

Reputation: 1208

The easiest way to implement zoom in android is using the WebView.

Place web view in each page of your ViewPager.

And do something like this:

public static String zoomHTML = "<!DOCTYPE html>\n" +
        "<html>\n" +
        "<head><title>Zoom Image</title></head>\n" +
        "<body>\n" +
        "<div>\n" +
        "    <img width=\"%d\" height=\"%d\" id=\"myCanvas\" src=\"data:image/png;base64,%s\"></img>\n" +
        "</div>\n" +
        "</body>\n" +
        "</html>";




String data = String.format(zoomHTML, screenHeight, screenWidth, base64StringImage);

zoomWebView.getSettings().setBuiltInZoomControls(true);
zoomWebView.getSettings().setSupportZoom(true);
zoomWebView.setInitialScale(100);
zoomWebView.loadDataWithBaseURL("", data, "text/html", "UTF-8", "");

Upvotes: 1

Related Questions