Android: How to get a custom View's height and width?

Rohith Nandakumar picture Rohith Nandakumar · Nov 2, 2010 · Viewed 128.3k times · Source

Possible Duplicate:
How to size an Android view based on its parent’s dimensions

how do I use getMeasuredWidth() and getMeasuredHeight? It always returns 0. what is the diffrence between this and getHeight() and getWidth()?

Answer

Paresh Mayani picture Paresh Mayani · Mar 15, 2012

Just got a solution to get height and width of a custom view:

@Override
protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld){
    super.onSizeChanged(xNew, yNew, xOld, yOld);

    viewWidth = xNew;
    viewHeight = yNew;
}

Its working in my case.