View 實(shí)例化之后昏兆,調(diào)用 view.measuredHeight 或 view.measuredWidth 為 0 .
如果想要獲取到真實(shí)的寬高值, 需要先調(diào)用一下一下代碼:
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
然后再獲取 View 的真實(shí)寬高
val height = view.measuredHeight
val width = view.measuredWidth