Android photoview Image zoom-in and zoom-out function ImageView,

Source: Internet
Author: User

Android photoview Image zoom-in and zoom-out function ImageView,

Android Image Browsing function zoom in and out

Double-click photoview or double-finger scaled ImageView

Use multi-touch and double-click.

Scroll to smooth rolling.


Github: https://github.com/chrisbanes/PhotoView


Actual results


Picture from: http://a.code4app.com/android/PhotoView/5241a4026803fa1327000000


Import the downloaded file to the IDE.




Add lib




Paste the photoview code:

/******************************************************************************* * Copyright 2011, 2012 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. *******************************************************************************/package uk.co.senab.photoview;import android.content.Context;import android.graphics.Bitmap;import android.graphics.Matrix;import android.graphics.RectF;import android.graphics.drawable.Drawable;import android.net.Uri;import android.util.AttributeSet;import android.view.GestureDetector;import android.widget.ImageView;import uk.co.senab.photoview.PhotoViewAttacher.OnMatrixChangedListener;import uk.co.senab.photoview.PhotoViewAttacher.OnPhotoTapListener;import uk.co.senab.photoview.PhotoViewAttacher.OnViewTapListener;public class PhotoView extends ImageView implements IPhotoView {    private final PhotoViewAttacher mAttacher;    private ScaleType mPendingScaleType;    public PhotoView(Context context) {        this(context, null);    }    public PhotoView(Context context, AttributeSet attr) {        this(context, attr, 0);    }    public PhotoView(Context context, AttributeSet attr, int defStyle) {        super(context, attr, defStyle);        super.setScaleType(ScaleType.MATRIX);        mAttacher = new PhotoViewAttacher(this);        if (null != mPendingScaleType) {            setScaleType(mPendingScaleType);            mPendingScaleType = null;        }    }    /**     * @deprecated use {@link #setRotationTo(float)}     */    @Override    public void setPhotoViewRotation(float rotationDegree) {        mAttacher.setRotationTo(rotationDegree);    }        @Override    public void setRotationTo(float rotationDegree) {        mAttacher.setRotationTo(rotationDegree);    }    @Override    public void setRotationBy(float rotationDegree) {        mAttacher.setRotationBy(rotationDegree);    }    @Override    public boolean canZoom() {        return mAttacher.canZoom();    }    @Override    public RectF getDisplayRect() {        return mAttacher.getDisplayRect();    }    @Override    public Matrix getDisplayMatrix() {        return mAttacher.getDrawMatrix();    }    @Override    public boolean setDisplayMatrix(Matrix finalRectangle) {        return mAttacher.setDisplayMatrix(finalRectangle);    }    @Override    @Deprecated    public float getMinScale() {        return getMinimumScale();    }    @Override    public float getMinimumScale() {        return mAttacher.getMinimumScale();    }    @Override    @Deprecated    public float getMidScale() {        return getMediumScale();    }    @Override    public float getMediumScale() {        return mAttacher.getMediumScale();    }    @Override    @Deprecated    public float getMaxScale() {        return getMaximumScale();    }    @Override    public float getMaximumScale() {        return mAttacher.getMaximumScale();    }    @Override    public float getScale() {        return mAttacher.getScale();    }    @Override    public ScaleType getScaleType() {        return mAttacher.getScaleType();    }    @Override    public void setAllowParentInterceptOnEdge(boolean allow) {        mAttacher.setAllowParentInterceptOnEdge(allow);    }    @Override    @Deprecated    public void setMinScale(float minScale) {        setMinimumScale(minScale);    }    @Override    public void setMinimumScale(float minimumScale) {        mAttacher.setMinimumScale(minimumScale);    }    @Override    @Deprecated    public void setMidScale(float midScale) {        setMediumScale(midScale);    }    @Override    public void setMediumScale(float mediumScale) {        mAttacher.setMediumScale(mediumScale);    }    @Override    @Deprecated    public void setMaxScale(float maxScale) {        setMaximumScale(maxScale);    }    @Override    public void setMaximumScale(float maximumScale) {        mAttacher.setMaximumScale(maximumScale);    }    @Override    // setImageBitmap calls through to this method    public void setImageDrawable(Drawable drawable) {        super.setImageDrawable(drawable);        if (null != mAttacher) {            mAttacher.update();        }    }    @Override    public void setImageResource(int resId) {        super.setImageResource(resId);        if (null != mAttacher) {            mAttacher.update();        }    }    @Override    public void setImageURI(Uri uri) {        super.setImageURI(uri);        if (null != mAttacher) {            mAttacher.update();        }    }    @Override    public void setOnMatrixChangeListener(OnMatrixChangedListener listener) {        mAttacher.setOnMatrixChangeListener(listener);    }    @Override    public void setOnLongClickListener(OnLongClickListener l) {        mAttacher.setOnLongClickListener(l);    }    @Override    public void setOnPhotoTapListener(OnPhotoTapListener listener) {        mAttacher.setOnPhotoTapListener(listener);    }    @Override    public OnPhotoTapListener getOnPhotoTapListener() {        return mAttacher.getOnPhotoTapListener();    }    @Override    public void setOnViewTapListener(OnViewTapListener listener) {        mAttacher.setOnViewTapListener(listener);    }    @Override    public OnViewTapListener getOnViewTapListener() {        return mAttacher.getOnViewTapListener();    }    @Override    public void setScale(float scale) {        mAttacher.setScale(scale);    }    @Override    public void setScale(float scale, boolean animate) {        mAttacher.setScale(scale, animate);    }    @Override    public void setScale(float scale, float focalX, float focalY, boolean animate) {        mAttacher.setScale(scale, focalX, focalY, animate);    }    @Override    public void setScaleType(ScaleType scaleType) {        if (null != mAttacher) {            mAttacher.setScaleType(scaleType);        } else {            mPendingScaleType = scaleType;        }    }    @Override    public void setZoomable(boolean zoomable) {        mAttacher.setZoomable(zoomable);    }    @Override    public Bitmap getVisibleRectangleBitmap() {        return mAttacher.getVisibleRectangleBitmap();    }    @Override    public void setZoomTransitionDuration(int milliseconds) {        mAttacher.setZoomTransitionDuration(milliseconds);    }    @Override    public IPhotoView getIPhotoViewImplementation() {        return mAttacher;    }    @Override    public void setOnDoubleTapListener(GestureDetector.OnDoubleTapListener newOnDoubleTapListener) {        mAttacher.setOnDoubleTapListener(newOnDoubleTapListener);    }    @Override    protected void onDetachedFromWindow() {        mAttacher.cleanup();        super.onDetachedFromWindow();    }}



Next, import lib to your project.


In your project, you only need to replace the original imageview with uk. co. senab. photoview. PhotoView in the xml file.

You can use



Very convenient and fast

Github: https://github.com/chrisbanes/PhotoView


Thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.