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. How to add external jar without Eclipse?

I'm trying to port an application in J2SE to Andriod (which I am just
learning).  My application is broken into several jars.  I'm using the
NetBeans Andriod API, not Eclipse, so I will probably have to do any
jar wranging the hard way.

I have access to all the sources I need and right now have build
scripts for all of them that produce J2SE code.  What would I need to
do to make Android jars?  How would I include them in my Android
application when I build it?  Do they become part of the apk, or do I
need to ship them separately?


2. Obscenities in dictionary apps

I noticed in the "Android Market Content Policy for Developers" that
obscenities are not allowed.

But what about for dictionary apps?

3. for Google attention

4. Run Android directly on Qemu

5. How can I change the look of the front screen of the Android?

6. Playing video in Android not showing the video, playing sound only with a still image

7. Build android middleware code for emulator