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
这是什么?PhotoView 是 Android ImageView 的子类,通过多点触控和双击手势添加缩放和平移功能。
这是一个独立应用,还是需要添加到我项目中的库?它是一个 Java 库(ImageView 的子类),你可以把它加入自己的 Android 应用中,它本身不是独立应用。
我该如何把它添加到我的项目中?在根目录的 build.gradle 中添加仓库,然后在模块的 build.gradle 中添加 PhotoView 依赖。
使用它除了 Gradle 和 Android 之外还需要其他东西吗?不需要,只要一个使用 Gradle 的标准 Android 项目即可;无需任何外部 SDK 或 API 密钥。
在 ViewPager 或 DrawerLayout 中使用时有什么需要注意的坑吗?重写了 onInterceptTouchEvent 的 ViewGroup(如 ViewPager 和 DrawerLayout)在缩小图片时可能抛出异常;你需要继承它们并捕获该异常,具体可参考 HackyDrawerLayout 示例。
它支持 Fresco,或者支持超大图片的子采样(subsampling)吗?都不支持。它不支持 Fresco,并且有意保持缩放功能简单,不做子采样;README 中指向了专门处理这些需求的其他独立项目。
PhotoView 开箱即用支持哪些手势?双指捏合缩放和双击缩放,以及带惯性滑动的平滑滚动,全部开箱即用。
我的应用能响应缩放或滚动的变化吗?可以。库会在显示的 Matrix 变化时通知你的应用,因此你可以根据当前的缩放或滚动位置更新界面;用户点击图片时也会收到通知。
它能在 ViewPager 中使用吗?可以,它的设计就是能很好地用在 ViewPager 这类可滚动的父容器中,不过 ViewPager 本身可能需要使用前面提到的 onInterceptTouchEvent 异常变通方法。
Creator
Baseflow
Size
16.5 MB
Stars
18.8K
Age
14y
Commits · 90 Days