I want to get the Real time (x,y) co-ordinates of currently focused view. I don't have much experience in android.I want to simulate focus based on input co-ordinates i.e. If I give input co-ordinates as (100,100) then wherever the focus is currently on screen it should go to the view in which the above co-ordinates fall. Please Help.
Asked
Active
Viewed 243 times
2
-
Kindly give reason for down voting – Triangle Jan 11 '16 at 11:43
-
how do you what to do this? programmatically? or via your computer? – Vyacheslav Jan 11 '16 at 11:44
-
As I already mention I want to simulate(code/program) focus.i.e parse source co-ordinates to a function and move the focus in the view in which the source co-ordinate lies. Use case is navigation in Android TV menu. – Triangle Jan 11 '16 at 11:47
-
Did you ever solve this? Would love to know how to get the focus coordinates – Mark Mayo Jan 15 '20 at 03:08
1 Answers
0
Use
Rect rectf = new Rect();
<imageView>or<view>.getLocalVisibleRect(rectf);
to retrieve the bounds of a view.
Before this just loop over your views. I think it should work.
https://stackoverflow.com/a/2226706/1979882
or this
int location[] = new int[2];
view.getLocationOnScreen(location);
https://stackoverflow.com/a/4692133/1979882
for global coordinates:
v.getLocationOnScreen()
or v.getLocationInWindow()

Community
- 1
- 1

Vyacheslav
- 26,359
- 19
- 112
- 194
-
Thanks Vyacheslav for the suggestions. I can get the bounds of view but it is with respect to the current view whereas I want the co-ordinates with respect to (0,0) (top left assumed) some base reference like in a graph paper. Can you help me out over this ? – Triangle Jan 11 '16 at 12:15
-
I tried with the edit also. It gives static co-ordinates. Moreover, v.getLocationOnScreen() gives co-ordinates for touch events. my question is for currently focus view. – Triangle Jan 12 '16 at 06:14