How to get the current size of the widget such as a button (Button) or (Surface) in the program (code) which has wrap_content in the xml fields of the width width file?

    2 answers 2

    view.getWidth(); view.getHeight(); 
    • this will work if the view has already been rendered - andreich
    • and how to force it to draw ?? I need to find out the size before drawing - Pavel
    • In general, I came to the conclusion that it is impossible to get dimensions before drawing, so I take them when I first draw! - Paul
     contentview.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); int width = contentview.getMeasuredWidth(); int height = contentview.getMeasuredHeight(); 
    • zeros returns - Paul