我正在使用带有场景 xml 的 MotionLayout:
<Transition
motion:constraintSetStart="@+id/start"
motion:constraintSetEnd="@+id/end"
>
<OnSwipe
motion:touchAnchorId="@+id/v_top_sheet"
motion:touchRegionId="@+id/v_top_sheet_touch_region"
motion:touchAnchorSide="bottom"
motion:dragDirection="dragDown" />
</Transition>
Run Code Online (Sandbox Code Playgroud)
2ConstraintSets只引用了 2 个视图 ID:v_notifications_container和v_top_sheet。
在我的活动中,我想将一个普通的 ClickListener 设置为这个 MotionLayout 中的其他视图之一:
iv_notification_status.setOnClickListener { Timber.d("Hello") }
Run Code Online (Sandbox Code Playgroud)
执行此行,但从未触发 ClickListener。我搜索了其他帖子,但其中大多数都涉及在与motion:touchAnchorId. 这不是这里的情况。ClickListener 设置为在 MotionLayout 设置中未曾提及的视图。如果我删除该app:layoutDescription属性,则单击有效。
我也尝试使用setOnTouchListener,但它也从未被调用过。
如何在 MotionLayout 中设置单击侦听器?
android onclicklistener android-constraintlayout android-motionlayout