How to find the Width of the a view before the view is displayed?

前端 未结 6 561
耶瑟儿~
耶瑟儿~ 2020-12-14 01:07

How to find the Width of the a view before the view is displayed? I do not want to add a custom view and tap the dimensions in the OnChanged().

6条回答
  •  不思量自难忘°
    2020-12-14 01:19

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    view.measure(size.x, size.y);
    int width = view.getMeasuredWidth();
    int height = view.getMeasuredHeight();
    

提交回复
热议问题