2

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.

Triangle
  • 1,477
  • 3
  • 22
  • 36

1 Answers1

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