Get height and width of a layout programmatically

前端 未结 16 1465
别那么骄傲
别那么骄傲 2020-11-27 13:55

I have designed an layout in which LinearLayout has 2 children LinearLayout and FrameLayout and in each child I put different views.

16条回答
  •  青春惊慌失措
    2020-11-27 14:43

    Just wanted to add an answer here, since Koltin has some convenience methods to do this, which are a lot less ugly than adding and removing a onGlobalLayoutListener:

    view.doOnLayout {
        it.measuredWidth
        it.measuredHeight
    }
    

    You can see more of the convinience methods here.

提交回复
热议问题