MotionLayout: MotionScene OnClick overrides setOnClickListener

后端 未结 7 1544
庸人自扰
庸人自扰 2021-02-13 19:02

I\'m just starting to play with MotionLayout. I have defined an activity layout using MotionLayout that uses a MotionScene to hide and sh

7条回答
  •  礼貌的吻别
    2021-02-13 19:22

    Here is simple solution:

    Just add this fun:

     @SuppressLint("ClickableViewAccessibility")
    fun View.setOnClick(clickEvent: () -> Unit) {
        this.setOnTouchListener { _, event ->
            if (event.action == MotionEvent.ACTION_UP) {
                clickEvent.invoke()
            }
            false
        }
    }
    

    This is how you use it:

    nextButton.setOnClick {
            //Do something 
    }
    

提交回复
热议问题