2

I have a FrameLayout for example like this:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 

xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/tools_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent">

    <ImageView
        android:id="@+id/imgv1"
        android:layout_width="300dp"
        android:layout_height="200dp"
        android:layout_gravity="center_vertical|center_horizontal"
        app:cameraCropOutput="true"
        app:cameraPlaySounds="false" />

    <ImageView
        android:id="@+id/imgv2"
        android:layout_width="300dp"
        android:layout_height="200dp"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        android:visibility="gone" />

</FrameLayout>

For imgv1 user can move, scale and rotate the image. After user moves the imgv1 with for example dragging it on the screen, if I use:

ImageView imgv1;
float xcoordinate, ycoordinate;

xcoordinate = imgv1.getX();
ycoordinate = imgv1.getY();

If I have not rotated the imgv1, then getX() and getY will return the position of the top left corner as can be seen here:

enter image description here

so in this case the value of xcoordinate is x and value of xcoordinate is y.

Now assume that I rotate the imgv1 and put the top left corner at the same location as before, i.e at (x and y) as shown here:

enter image description here

Now when I run:

xcoordinate = imgv1.getX();       
ycoordinate = imgv1.getY();

I don't get x and y anymore, depending on the angle I get different strange values. What are these returned values and why they are not x and y?

On some sense, after the rotation, there is no top left corner. So does getX() returns the leftmost point which is the x-value for the bottom left of the rotated rectangle and getY() returns y?

TJ1
  • 7,578
  • 19
  • 76
  • 119
  • The question for me here is what do `getX()` and `getY()` return when the ImageView is rotated? Do you have any answer to this question? – TJ1 May 11 '18 at 12:42
  • No, I just want to understand what `getX()` and `getY()` return when ImageView is rotated. I think it is a valid question and I like to know what happens, not for my specific application but in general. – TJ1 May 11 '18 at 12:50
  • if you're referring by getX() and getY() to the methods inside the onTouchEvent method ,then those two returns the last coordinates of the point where you last touched the screen before you remove your finger. So by that logic if you're rotating your rectangle from the bottom right then the coordinates you're getting at the end are the ones of the bottom right corner not the top left one. – user 007 May 11 '18 at 13:06
  • Thanks for the comment. I don't think `getX()` and `getY()` return the coordinates of the last touch. For example, if I touch the middle of the rectangle and move it so its top right is at `(x,y)`, these two methods return exactly `x` and `y`. – TJ1 May 11 '18 at 13:11
  • On my second drawing, can you please tell me what `getX()` and `getY()` are going to return? They do not return `x` and `y`. Can you dhow your answer on a plot or something? – TJ1 May 11 '18 at 14:22
  • No what you showed as gray rectangle left top is not what is returned. – TJ1 May 13 '18 at 07:27

0 Answers0