Android developmentAndroid tutorial

How to used ImageView Zoom-in and Zoom-Out in android

Hi Everyone in this Article I am sharing How to used ImageView Zoom-in and Zoom-Out in android. hare is an easy way to used zoon in and zoom out in recycler view list. I am used a GitHub Library  com.github.chrisbanes.photoview.PhotoView.  

In this android programming code example, we are going the explore how to pinch ImageView to zoom-in and zoom-out in android. I am providing these code I am used Pinch-to-zoom with multi-touch gestures In recyclerView List.

STEPS

  1. Add this in build. Gradle implementation com.github.chrisbanes.photoview.PhotoView to have access to Zoomage library classes.
  2. Add an com.github.chrisbanes.photoview.PhotoView in XML layout file
  3. Get the instance of the photoview.PhotoView in the Activity class.
  4. You can use some of the photoview.PhotoViewattributes depending on your use-case.

build.gradle

compile 'com.github.chrisbanes:PhotoView:2.1.3'

Step 1: Create an XML Layout for Photo Zoom In zoom out.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent">


    <com.github.chrisbanes.photoview.PhotoView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="500dp"
        tools:ignore="MissingPrefix" />

</LinearLayout>

Step 2:  Used this Code for Image Zoom in whare you want to Zoom ImageView. 

I am Using in a recycler view list Image. image comes from server  API and Show it using Picasso Library. in Adupte class you used it. In public void onBindViewHolder(RecyclerView.ViewHolder holder, int position )  Method, you can used it.

Invst_Doc.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        AlertDialog.Builder mBuilder = new AlertDialog.Builder(context);
        View mView = inflater.from(view.getContext()).inflate(R.layout.dialog_custom_layout, null);
        PhotoView photoView = mView.findViewById(R.id.imageView);
            Picasso.with(context)
                    .load(body_front)
                    .placeholder(R.drawable.icon_user)
                    .into(photoView);
        mBuilder.setView(mView);
        AlertDialog mDialog = mBuilder.create();
        mDialog.show();
    }
});

Use an AlertDialog Box and here you can be used your Dialog XML layout.

 View mView = inflater.from(view.getContext()).inflate(R.layout.dialog_custom_layout, null);
PhotoView photoView = mView.findViewById(R.id.imageView);

add these code whare you want used Imageview Zoom In Zoom Out and Set Image On PhotoView