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

前端 未结 7 2020
悲哀的现实
悲哀的现实 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:35

    You have to wait until the onSizeChanged() method is called before you can reliably determine the View size.

    This is called during layout when the size of this view has changed. If you were just added to the view hierarchy, you're called with the old values of 0.

提交回复
热议问题