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

HI,
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 ?

Thanks
Rohit BajajAsked:
Who is Participating?
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.

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

also refer to http://developer.android.com/reference/android/view/View.html for more details.
0
Rohit BajajAuthor Commented:
Hi,
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
0
FloraCommented:
not sure if i understood your question correctly.

are you trying for multiple screen support?  here is the useful andriod developer best practice link
https://guides.codepath.com/android/Working-with-the-ImageView

http://developer.android.com/guide/practices/screens_support.html
0
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();
            getWindowManager().getDefaultDisplay().getMetrics(dm);
            int w = dm.widthPixels;
            int h = dm.heightPixels;

Open in new window


Thanks & Regards,
Krunal T. Tailor
0

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
Android

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.