how to get the height and widht of the views in an android activity in pixels

I have an activity running on my android phone. Each view is having some pixels width and height on the phone screen. I want to find out how much height and width in pixels on the phone screen does each view take. How can i find out this ?

Rohit BajajAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

you get the pixel you need by calling myView.getParent() and with getWidth() and getHeight()

also refer to for more details.
Rohit BajajAuthor Commented:
That will give me view height and width. what if there is a background drawable in the view... Although i can find out the width and height in pixels for this drawable image on my computer. But when this will be rendered on my mobile its width and height may vary. How do i find out the exact width and height on my android phone
not sure if i understood your question correctly.

are you trying for multiple screen support?  here is the useful andriod developer best practice link
KRUNAL TAILORFreelance Mobile DeveloperCommented:
Hi Robinsuri,

Have you tried this snippet before to get pixels of height and width of device.

DisplayMetrics dm = new DisplayMetrics();
            int w = dm.widthPixels;
            int h = dm.heightPixels;

Open in new window

Thanks & Regards,
Krunal T. Tailor

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.