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:
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:
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
?