Reputation: 531
I'm new to android.What is the easiest way to pop an imageview to full screen (with pinch zoom enabled),when it is tapped, just like whatsapp images? I'm loading my images in a recycler view via Glide. Thank you for your time and reply.
Upvotes: 6
Views: 12367
Reputation: 1
This is the working code for me for a single image and using glide Finally I found something similar to WhatsApp. I was digging over the internet for three days now I found a solution.
new StfalconImageViewer.Builder<String>(context, new ArrayList<>(Arrays.asList(messageModel.get(position).getUrl().trim())), new ImageLoader<String>() {
@Override
public void loadImage(ImageView imageView, String image) {
Glide.with(context)
.load(image)
.into(imageView);
}
}).show();
Upvotes: 0
Reputation: 1595
There is a library called StfalconImageViewer. It supports transition animation for image opening and closing, pinch-to-zoom and swipe-to-dismiss gestures out of the box. Using Glide it'll be done like this:
new StfalconImageViewer.Builder<>(context, images, new ImageLoader<String>() {
@Override
public void loadImage(ImageView imageView, String imageUrl) {
Glide.with(context).load(imageUrl).into(imageView)
}
}).show();
Hope this helps!
Upvotes: 12
Reputation: 342
I used PhotoView (https://github.com/chrisbanes/PhotoView) and Glide (https://github.com/bumptech/glide).
I created full screen activity first and put PhotoView in layout.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
tools:context=".PhotoviewerActivity">
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout>
Then, I pass image URL that I want to show to the full screen activity and load image with Glide like below.
val imageUrl = intent.getStringExtra(IMAGE_URL)
Glide.with(applicationContext).load(imageUrl).into(fullscreen_content)
You can remove all not needed code from full screen layout and also disable from full screen activity code. These codes are written in Kotlin.
Upvotes: 12