我正在将MotionLayout与scene-xml一起使用:
<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>
[2 ConstraintSets
仅引用2个视图ID:v_notifications_container
和v_top_sheet
。
在我的活动中,我想为该MotionLayout中的其他视图之一设置普通的ClickListener:
iv_notification_status.setOnClickListener { Timber.d("Hello") }
此行已执行,但从未触发ClickListener。我搜索了其他帖子,但是大多数帖子都是在motion:touchAnchorId
的同一视图上设置ClickListener的。这里不是这种情况。 ClickListener设置为在MotionLayout设置中未曾提及的View。如果删除app:layoutDescription
属性,则单击有效。
我也尝试使用setOnTouchListener
,但也从未使用过。
如何在MotionLayout中设置点击侦听器?
要在视图上设置onClick操作,请使用:
android:onClick="handleAction"
在MotionLayout文件内部,并在您的类中定义“ handleAction”。