Sunday, February 27, 2011

how to get width and height dimensions of a customView (extends View) in Android

So what I was trying to do is get the following dimensions of ONE out of the TWO framelayouts that I had put on my android application.

As obvious as it is, I went to the Android Developer's website to look up the available methods for finding width and height. And it said android.view.View.getWidth() and android.view.View.getHeight() will do just the thing. But..... it did NOT do the thing that way.

I had been looking around all over the forums and sites to find the solution.... LOTs of people are asking this questions, but i couldn't find that absolute solution from any of the forums. So, once I figured out the way, I thought of putting the solution up on my blog.

At first, here is how the android activity looks:

Activity with a Toast Message showing
width and height of the green frame
Now, here is the xml layout file that was used in this example