How to reference “this” within anonymous listeners when using short notation?

后端 未结 3 1786
北海茫月
北海茫月 2021-01-04 04:38

In Kotlin, is there a way to reference the listener instance when using this short notation for anonymous classes? In this case this refers to outer context (e.

3条回答
  •  走了就别回头了
    2021-01-04 04:53

     val animation = object : Animation() {
            override fun applyTransformation(interpolatedTime: Float, t: Transformation) {
                val layoutParam: RelativeLayout.LayoutParams? = playerView.layoutParams as RelativeLayout.LayoutParams?
                layoutParam?.topMargin = convertDpToPixel(position, this@SurahActivity).toInt()
                playerView.layoutParams = layoutParam
            }
        }
    

提交回复
热议问题