need help in getting screen coordinates of a view

by kavitha » Mon, 23 Mar 2009 08:04:46 GMT

Sponsored Links
 Hii All,

I am developing a game in android and i want to capture screen
coordinates of a view(ImageView) which is embedded in frame.

Hierarchy is
<LinearLayout android android:layout_height="fill_parent"
android:layout_width="fill_parent" >
      <RelativeLayout android:layout_height=fill_parent"
android:layout_width="fill_parent" >
            <FrameLayout android:layout_height="wrap_content"

At run time i am attaching two image views for frame layout.I wanted
to capture screen coordinates of frame layout.But Couldnt do it.if i

(FrameLayout) f=(FrameLayout)findViewById(;
int[] loc = new int[2];

I get Null Pointer Exception for getLocationOnScreen() method.

If I try to get f.getLeft() and f.getRight() they return as 0 coordinates.

Can anyone please tell me how to find location on screen of a view.

It is very urgent.Please help.



Other Threads

1. a2dp (WAS fix alsa compilation problem Eclair)

Sorry find :( external/bluetooth for sure :)


2. AudioTrack sanity test

I am trying to determine if I should go the ndk way to work on a music
synth app, but first wanted to do a sanity check in the java layer by
testing how many sine tones i could play concurrently, and so I tried
this. And it's pretty low: I can only play about 4 or 5 tones before
the obtainBuffer timeouts start increasing in number. Also, changing
the media volume while the tones are playing disrupts the output.
These are the basic settings for each of the tones:
- fs = 11025
- AudioTrack.MODE_STREAM
I would like to know how one can best avoid obtainbuffer timeout


3. ActivityGroup and subactivities Lifetime.

4. AlertBuildeer Problem

5. QVGA854 AVD not displaying properly

6. Alternatives to using 'createScaledBitmap' when adding 3D

7. Why are iPhone apps prettier than Android apps?