Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine an Android View's size in pixels?

Tags:

android

Is there a direct programmatic way to get a fill_parent View's pixel height and width? For instance a view in a grid layout in a tab. Or do I have to get the window size and subtract the static sizes of the views around it?

like image 665
Loren Avatar asked Mar 29 '12 23:03

Loren


1 Answers

You can get the views parent by calling myView.getParent() and with getWidth() and getHeight() you get the pixel you need. the documentation is providing more information to this topic http://developer.android.com/reference/android/view/View.html

like image 141
andreasg Avatar answered Nov 09 '22 10:11

andreasg