I am trying to create a zoomable container and I am targeting API 14+
In my onScale (i am using the ScaleGestureDetector to detect pinch-zoom) I am doing something like this:
public boolean onScale (ScaleGestureDetector detector) {
float scaleFactor = detector.getScaleFactor();
setScaleX(getScaleX() * scaleFactor);
setScaleY(getScaleY() * scaleFactor);
return true;
};
It works but the zoom is not smooth. In fact it noticeably flickers.
I also tried it with hardware layer thinking that the scaling would happen on the GPU once the texture was uploaded and thus would be super fast. But it made no difference - the zoom is not smooth and flickers weirdly sometimes.
What am I doing wrong?
Several people experienced screen flickering when using Zoom conferencing and a zSpace system when they enabled screen sharing. Because of its higher refresh rate, zSpace systems are typically unable to handle a refresh rate that is high enough to handle Zoom's system.
What is pinch-to-zoom? Pinch-to-zoom is when a user uses two fingers and pinches to zoom in or out on their mobile device. While it wasn't present on the original touchscreen phones, pinch-to-zoom is now a nearly universal motion for adjusting size on touchscreen devices.
Tap anywhere on the screen, except the keyboard or navigation bar. Drag 2 fingers to move around the screen. Pinch with 2 fingers to adjust zoom. To stop magnification, use your magnification shortcut again.
Does the flicker look like the view flipping back and forth between zoomed and not-zoomed? That's caused by having the ScaleGestureDetector
handling motion events from the same view that you're scaling. When you setScaleX()
that changes the coordinates of the touch, which triggers a new touch event interpreted as reversing the zoom you just applied.
Put the content of your zoomable view inside a single child FrameLayout
and set the scale on that view instead.
I've posted a working pinch-zoom layout here: https://gist.github.com/anorth/9845602
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With