Loren
Loren

Reputation: 14896

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

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?

Upvotes: 18

Views: 25024

Answers (2)

mmaitlen
mmaitlen

Reputation: 822

There's the onMeasure() method, not sure if that will do what you need. http://developer.android.com/guide/topics/ui/custom-components.html

Upvotes: 0

andreasg
andreasg

Reputation: 1090

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

Upvotes: 19

Related Questions