PhotoView README

The project's README from github.com/Baseflow/PhotoView. As one markdown file: README.md.

PhotoView

PhotoView aims to help produce an easily usable implementation of a zooming Android ImageView.

[

Dependency

Add this in your root build.gradle file (not your module build.gradle file):

allprojects {
    repositories {
        maven { url "https://www.jitpack.io" }
    }
}

buildscript {
    repositories {
        maven { url "https://www.jitpack.io" }
    }	
}

Then, add the library to your module build.gradle

dependencies {
    implementation 'com.github.chrisbanes:PhotoView:latest.release.here'
}

Features

Usage

There is a sample provided which shows how to use the library in a more advanced way, but for completeness, here is all that is required to get PhotoView working:

<com.github.chrisbanes.photoview.PhotoView
    android:id="@+id/photo_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
photoView.setImageResource(R.drawable.image);

That's it!

Issues With ViewGroups

There are some ViewGroups (ones that utilize onInterceptTouchEvent) that throw exceptions when a PhotoView is placed within them, most notably ViewPager and DrawerLayout. This is a framework issue that has not been resolved. In order to prevent this exception (which typically occurs when you zoom out), take a look at HackyDrawerLayout and you can see the solution is to simply catch the exception. Any ViewGroup which uses onInterceptTouchEvent will also need to be extended and exceptions caught. Use the HackyDrawerLayout as a template of how to do so. The basic implementation is:

public class HackyProblematicViewGroup extends ProblematicViewGroup {

    public HackyProblematicViewGroup(Context context) {
        super(context);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        try {
            return super.onInterceptTouchEvent(ev);
        } catch (IllegalArgumentException e) {
						//uncomment if you really want to see these errors
            //e.printStackTrace();
            return false;
        }
    }
}

Usage with Fresco

Due to the complex nature of Fresco, this library does not currently support Fresco. See this project as an alternative solution.

Subsampling Support

This library aims to keep the zooming implementation simple. If you are looking for an implementation that supports subsampling, check out this project

License

Copyright 2018 Chris Banes

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

PhotoView (Baseflow/PhotoView)

Searching Database…

18.8K ·GitHub
What is this?PhotoView is an Android ImageView subclass that adds zooming and panning support via multi-touch and double-tap gestures.
Is this a standalone app or a library I add to my project?It is a Java library (an ImageView subclass) you drop into your own Android app, not a standalone app.
How do I add it to my project?Add the repository to your root build.gradle, then add the PhotoView dependency to your module build.gradle.
Do I need anything besides Gradle and Android to use it?No, just a standard Android project with Gradle; there are no external SDKs or API keys required.
Any gotchas when using it inside ViewPager or DrawerLayout?ViewGroups that override onInterceptTouchEvent, like ViewPager and DrawerLayout, can throw exceptions when zooming out; you need to extend them and catch the exception, as shown in the HackyDrawerLayout example.
Does it work with Fresco or support subsampling for huge images?No, it does not support Fresco, and it intentionally keeps zooming simple without subsampling; the README points to separate alternative projects for those needs.
What gestures does PhotoView support out of the box?Pinch-to-zoom and double-tap zooming, plus smooth scrolling with fling, all working out of the box.
Can my app react to zoom or scroll changes?Yes, the library notifies your app when the displayed Matrix changes, so you can update your UI based on current zoom or scroll position, and it also notifies you when the user taps the photo.
Does it work inside a ViewPager?Yes, it is designed to work perfectly when used inside a scrolling parent like ViewPager, though ViewPager itself may need the onInterceptTouchEvent exception workaround.
Creator
Baseflow
Size
16.5 MB
Stars
18.8K
Age
14y
Commits · 90 Days