alexvasilkov / GestureViews

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

State.getX in onStateChangeListener #169

Closed Equin closed 3 years ago

Equin commented 3 years ago

Hi, what is State.getX and State.getY in new state of onStateChangeListener ? Is it new screen top left corner ? Is it take scale in calculation of its value ? Or what is it ? Thanks.

alexvasilkov commented 3 years ago

It is top-left image's corner position in ImageView coordinates. The state is converted into matrix and applied with ImageView.setImageMatrix()

Equin commented 3 years ago

@alexvasilkov oh, sorry, forgot to say. i am using GestureFrameLayout.
When i zoomIn this layout i am getting x:-1600, y:-600, scale:3; when zoomOut its x:0, y:0, scale:1; So in ZoomIn state x and y its top-left corner of frameLayout? How can i get coordinates of element in zoommed frameLayout ? I want to place balloon popup for that element, but it has wrong anchore point when layout is zoomed. and i dont know how to calculate offsets to positionate this balloon. Can you help me, please ?

alexvasilkov commented 3 years ago

Yes, in GestureFrameLayout the state position is relative to top-left corner of the layout. The state is converted into a matrix and applied with canvas.concat(matrix).

If you have anchor coordinates in layout's coordinates then you can calculate visible coordinates like this:

state.get(matrix);
tmpPointArray[0] = anchorX;
tmpPointArray[1] = anchorY;
matrix.mapPoints(tmpPointArray);
float newX = tmpPointArray[0];
float newY = tmpPointArray[1];