How To Get Exact Position In Pixels Of My Textview?
I have a smartphone of 2560 x 1440 px. Now I am using this function for my TextView: int[] locationOnScreen = new int[2]; txtAp.GetLocationInWindow(locationOnScreen); It is suppos
Solution 1:
I have a smartphone of 2560 x 1440 px... My
TextView
is pretty much in the middle of the screen, so supposedly at (1280,770).
Not correct, unless you talk about the center of the TextView
. Any view is rendered on screen within its rectangle, so its coordinates are considered to be of [left, top, right, bottom].
The GetLocationInWindow()
method returns (left, top) coordinates of a view. So (x = 69, y = 1111) looks to be meaningful for the left top corner of your TextView
located in the middle of screen.
Important note: GetLocationInWindow()
returns the coordinates w.r.t the root view, not actual window. You should take the status bar height into consideration. And here is how you can calculate Height of status bar in Android.
Post a Comment for "How To Get Exact Position In Pixels Of My Textview?"