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()
?
You can use the following method to get the width and height of the view, For example, int height = yourView. getLayoutParams(). height; int width = yourView.
First get layout params using view. getLayoutParams(). Second then set the height and width value then last set the layout params of view.
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.
Don't try to get them inside its constructor. Try Call them in onDraw()
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With