alexvasilkov / GestureViews

ImageView and FrameLayout with gestures control and position animation
Apache License 2.0
2.37k stars 384 forks source link

GestureImageView overrides scaleType #183

Closed ParticleCore closed 1 year ago

ParticleCore commented 1 year ago

Currently GestureImageView overrides the scaleType in its constructor to ImageView.ScaleType.MATRIX.

This is a problem if we want to use it with Glide for an image that is meant to fill the device screen because since we are unable to change the scale type we are forced to use match_parent on the target view in which the animation ends and Glide uses to load the image.

Because of the way Glide was designed match_parent will cause it to create an image as big as the biggest dimension of the imageview, and this means that when the user tries to load a thin horizontal image, Glide will upscale it proportionally to become as tall as the device screen size, and this results in a really wide image which ends up causing the following crash in issue #180

Overriding the image size individually is not an option since in my case that size is not known before the image is loaded from the network, thus setting the scale would be the only solution.

This is not a problem if I use a plain ImageView instead of GestureImageView, but if I do that then the resizing animation (in the "Image Animation" demo examples) from partially visible images in the list to full size viewer will be broken, as in it doesn't animate smoothly from a partially visible size, instead it instantly shows the final size in miniature and grows into the final size.

Is there a way to work around this problem?

ParticleCore commented 1 year ago

Sorry about this, it seems that Glide has its own fitCenter method which mimics the ImageView scale type but instead does it directly in the resource it loads. It is not a perfect solution since it will downscale bigger images, but given all the other restrictions this is an acceptable compromise. I will leave this open in case the developer has any other useful insights, otherwise this issue can be closed.

alexvasilkov commented 1 year ago

There is no way this library can work without setting scaleType to matrix, that's the core API that drives image panning / zooming / rotation. See also #128.

You have to control images sizes yourself, and Glide has a very extensive API to control the way downloaded images are scaled. In most cases you don't want very big images to avoid OOMs, you can downsample them like this:

  Glide.with(...)
    ...
    .override(3072, 3072) // + AT_MOST -> image size in 1536..3072
    .dontTransform()
    .downsample(DownsampleStrategy.AT_MOST)
    ...