Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I used Glide library to load image into imageView and I don't know how to make image pinch to zoomable

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    //Variables
    ImageView imageView;
    imageView = (ImageView) findViewById(R.id.imageView);

    //Loading into ImageView
    Glide.with(this)
            .load("http://vrijeme.hr/bradar.gif")
            .into(imageView);
}

I tried using Picasso too and then connecting it with PhotoView library but it didn't do anything, when I tried pinch to zoom it didn't zoom at all, here is part of that code:

ImageView imageView;
PhotoViewAttacher photoView;

imageView = (ImageView) findViewById(R.id.imageView);
photoView = new PhotoViewAttacher(imageView);
Picasso.with(this)
       .load("link")
       .resize(1080,80)
       .into(imageView);
like image 494
Towelie Avatar asked Apr 26 '17 16:04

Towelie


People also ask

Which glide method do you use to indicate the ImageView that will contain the loaded image?

Which Glide method do you use to indicate the ImageView that will contain the loaded image? How do you specify a placeholder image to show when Glide is loading? Use the into() method with a drawable.

How do you load a drawable image with Glide?

into(myImageView); Load method of Glide also accept drawable object as a parameter to load image. You just have to get the drawable object from your drawable image and pass it to the load method. I wanted rounded-corner of image and that's why I used Glide.


1 Answers

This library here called PhotoView is quite popular.
https://github.com/chrisbanes/PhotoView

With 13,500+ stars, 30+ contributors backing it, so many people using it and how easy it is to integrate into a project, it almost feels like a standard.

It's also compatible with Glide ^.^


Installation (Official documentation by chrisbanes)

Add this in your root build.gradle file (not your module build.gradle file):

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

Then, add the library to your module build.gradle

dependencies {
    implementation 'com.github.chrisbanes:PhotoView:latest.release.here'
}

At that time of writing, latest.release.here is 2.1.4.


Usage (Official documentation by chrisbanes)

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!


Usage with Glide

Nothing changes!!

PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
Glide.with(this).load(imageUrl).into(photoView);
like image 139
Ricky Dam Avatar answered Sep 18 '22 08:09

Ricky Dam