Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getX() does not return correct values

Tags:

android

Let's assume an ImageView, which when added to my layout(relative layout), with no scaling(the scale is 1). If I call getX(), it returns the correct X position.

However, if I now call setScaleX() with 2, and then call getX(), I get a totally different value. If I divide this value by the scale factor(2), it still doesn't give me the actual position. How do I get the actual position? Why is getX() returning absurdly large values which keep growing when the ImageView is scaled?

This is the case for the Y coordinate as well.

like image 707
judepereira Avatar asked Apr 17 '26 02:04

judepereira


1 Answers

Instead of using getX() and getY() to get the position of the view, I'm now using getMatrix(), and obtaining the translation values from this matrix. This seems to work well! It reports the correct X and Y values.

like image 163
judepereira Avatar answered Apr 18 '26 15:04

judepereira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!