getWidth() and getHeight() always returning 0. Custom view

前端 未结 7 2030
悲哀的现实
悲哀的现实 2020-12-09 09:11

In a Fragment, I am inflating a Layout with multiple child View. I need to get the dimensions (width and height) of one of them which is a custom view.

Inside the

7条回答
  •  不思量自难忘°
    2020-12-09 09:32

    Try checking in onWindowFocusChanged and it should have valid values:

    public void onWindowFocusChanged (boolean hasFocus) { }
    

    I had a similar issue where I needed to get width and height of a widget and this was the function in which I could guarantee the widget reported it's correct size.

提交回复
热议问题