How to reference a lambda from inside it?

后端 未结 3 2032
温柔的废话
温柔的废话 2020-12-30 00:44

I am trying to get height of a view in onCreate method but I couldn\'t find any way to remove OnGlobalLayoutListener.

In Java (working):

containerLay         


        
3条回答
  •  隐瞒了意图╮
    2020-12-30 01:15

    Referencing a lambda from inside it is not supported.

    As a workaround, you might use anonymous object instead of lambda SAM-converted to Java functional interface OnGlobalLayoutListener:

    containerLayout.viewTreeObserver.addOnGlobalLayoutListener(object: OnGlobalLayoutListener {
        override fun onGlobalLayout() {
            // your code here. `this` should work
        }
    })
    

提交回复
热议问题