ImageView library that allows full screen pinch zoom?

ImageView library that allows full screen pinch zoom?



I have a FrameLayout that contains an ImageView which I'd like to be able to zoom in on. How can I enable a "pinch-to-zoom" in the ImageView?



I'd like to be able to not have the zooming be restricted to the size of the ImageView but rather to the size of the containing FrameLayout as illustrated here (different app):



enter image description hereenter image description here





btw , when you use hammer.js even if you prevented scale within your pages / form , it will allow zooming for the images when you load your hammer.js librarry . it will work on any platform ios , android , windows phones , web browsers etc.. i posted 2 examples for you for images works over web browser. refer to the site official of hammer.js for any additional information
– Ahmed Shahin
Sep 1 at 1:01




2 Answers
2



There's a library that does exactly what you need - https://github.com/davemorrissey/subsampling-scale-image-view



Replace the ImageView in your layout with the SubsamplingScaleImageView from the library. Then in your fragment or activity, get a reference to the SubsamplingScaleImageView and set the image using either a resource, asset or uri like the following:


ImageView


SubsamplingScaleImageView


SubsamplingScaleImageView


SubsamplingScaleImageView imageView =
(SubsamplingScaleImageView) findViewById(id.imageView);
imageView.setImage(ImageSource.resource(R.drawable.monkey));
imageView.setImage(ImageSource.asset("map.png"));
imageView.setImage(ImageSource.uri("/sdcard/DCIM/DSCM00123.JPG"));



The image should be scaled automatically when you pinch it, without needing to configure anything extra.





Tohu, please don't just post some tool or library as an answer. At least demonstrate how it solves the problem in the answer itself.
– Shree
Sep 1 at 4:22





I actually was looking for a library so this works! I'll be sure to specify next time I ask a question though
– Isaac Perez
Sep 1 at 15:03





@IsaacPerez If this is the answer you were looking for, could you please mark it as answered?
– Tohu
Sep 8 at 1:32



you can use android studio for doing that ,
here is steps how to achive it .



you may refer to this link to use it by



1- Open up Android Studio and create a new project and give it a name, in our case we’ve named it (ImageZoom), choose API 16 as the minimum SDK, then choose a blank activity, click “Finish” and wait for Android Studio to build your project.



enter image description here



2- Open up build.gradle (Module:app) and add PhotoView library.



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



3- Now you need to open up build.gradle (Project) and you need to add this line maven url "https://jitpack.io" inside (allprojects) tag.


allprojects
repositories
google()
jcenter()
maven url "https://jitpack.io"




4- Sync the project by clicking on (Sync Now).



android studio sync gradle file
Android studio sync gradle file. (Large preview)



5- Open activity_main.xml file, here you will add 3 views:
– Android ImageView that will hold the picture.
– Android TextView for the image title and description.



6-
Add Android ImageView and make sure that you have added the image that you want to use for the ImageView inside the project drawable folder.



7-:


ImageView
android:id="@+id/ivIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/nature" />



8- Add some margin above the ImageView and place it in the center.


<ImageView
android:id="@+id/ivIcon"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
app:srcCompat="@drawable/nature" />



9- When you tap on the ImageView inside Android Studio preview window, you will see an empty space from top and bottom of the ImageView. You can fix that by using android:scaleType="centerCrop" which allow the image to fill the remaining space.


<ImageView
android:id="@+id/ivIcon"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:scaleType="centerCrop"
app:srcCompat="@drawable/nature" />



10- when you tap on the ImageView inside Android Studio preview window, you will see an empty space from top and bottom of the ImageView. You can fix that by using android:scaleType="centerCrop" which allow the image to fill the remaining space.


<ImageView
android:id="@+id/ivIcon"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:scaleType="centerCrop"
app:srcCompat="@drawable/nature" />



When you tap on the ImageView inside Android Studio preview window, you will see an empty space from top and bottom of the ImageView. You can fix that by using android:scaleType="centerCrop" which allow the image to fill the remaining space.


<ImageView
android:id="@+id/ivIcon"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:scaleType="centerCrop"
app:srcCompat="@drawable/nature" />



Add Android TextView which will hold the name of the picture, this TextView will be placed below ImageView (ivIcon) in the center, add some margin from the top, try to increase text size to (20sp) and change text style to (italic and bold).


<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="@+id/ivIcon"
android:text="@string/flower_name"
android:layout_centerHorizontal="true"
android:textSize="20sp"
android:textStyle="italic|bold" />



11- Now you add the final TextView for this layout which will hold the description about the picture, this TextView will be placed below (tvName), try to increase text size to (16sp) and don’t forget to add some margin from the top so that it doesn’t appear to close with (tvName) TextView.


<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvName"
android:textSize="16sp"
android:layout_marginTop="5dp"
android:text="@string/flower_description" />



12- Now you are done working on activity_main.xml file, next you need to open up MainActivity.java file and initialize Android ImageView and Android AlertDialog.



13- Initialize ImageView (ivIcon).


ImageView mIcon = findViewById(R.id.ivIcon);



14- Next you need to change the shape of ImageView (ivIcon) to circle using RoundedBitmapDrawable and Bitmap.


Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.nature);
RoundedBitmapDrawable mDrawable =
RoundedBitmapDrawableFactory.create(getResources(), bitmap);
mDrawable.setCircular(true);
mIcon.setImageDrawable(mDrawable);



15- Build and run the app to see the progress.



16- Now you need to work on Android AlertDialog, the AlertDialog will appear on the screen when you try to tap on ImageView (ivIcon). Before you start that, you first need to create another layout file that you will use it later for AlertDialog



16- Now you need to work on Android AlertDialog, the AlertDialog will appear on the screen when you try to tap on ImageView (ivIcon). Before you start that, you first need to create another layout file that you will use it later for AlertDialog.



17- Create a new layout file and name it (dialog_custom_layout.xml), this file will have a PhotoView that will match the width and height of the screen.


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



18- Now go back to MainActivity.java file, to be able to tap on the ImageView you will need to use setOnClickListener and inside onClick is where you will create AlertDialog.


mIcon.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
AlertDialog.Builder mBuilder = new
AlertDialog.Builder(MainActivity.this);
View mView =
getLayoutInflater().inflate(R.layout.dialog_custom_layout,
null);
PhotoView photoView = mView.findViewById(R.id.imageView);
photoView.setImageResource(R.drawable.nature);
mBuilder.setView(mView);
AlertDialog mDialog = mBuilder.create();
mDialog.show();

);



19- Build and run the app to test out Android pinch and zoom function.
enter image description here



20- Hmm it seems that the image doesn’t fill the entire AlertDialog! You can actually fix it by using android:scaleType="centerCrop".


<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />



21- Build and run the app to see the result.



22- Great now you have a fully working app with pinch to zoom Android function 🙂



enter image description here



enter image description hereenter image description here



enter image description hereenter image description here



enter image description here



enter image description here





This solution is not for native app.
– Amolpskamble
Sep 1 at 4:57





i am not following you , i actully thought you are using android browser in native app , i mean there is browser you can place in there and the browser can support this js . if its not browser , why would you look for js librarry , why dont you use the tools in android it self then ?? i cannot understand what you are saying .. conflict !!
– Ahmed Shahin
Sep 1 at 6:04





In the question user has mentioned, he using ImageView inside FarmeLayout. Both the components are native to Android and therefore solution should be native to Android. Your solution is acceptable if WebView or any other similar component is used.
– Amolpskamble
Sep 1 at 6:19



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế