androidandroid-photoview

PhotoView fit screen height maintain aspect ratio


I cant scaletype for my PhotoView that lets me pan side to side on an image while being full-screen, without cropping the sides using Photo.ScaleType.CENTER_CROP. How would I go about doing this?

This is what I want (where the user can pan side to side to view the whole image): enter image description here

This is what I get (when using ScaleType.CENTER_CROP, which is closest to what I'm going for but because of the CROP, doesnt allow panning side to side.):

enter image description here


Solution

  • I fixed it by using a PhotoViewAttacher like this:

    ImageView imageView = (ImageView) findViewById(R.id.preview);
    PhotoViewAttacher photoViewAttacher = new PhotoViewAttacher(imageView);
    photoViewAttacher.setScaleType(ImageView.ScaleType.CENTER_CROP)
    

    and then using an ImageView (id.preview) with the ScaleType in the XML set as Matrix. (otherwise it wont work)