Skip to content

Instantly share code, notes, and snippets.

class ItemTouchInterceptor : RecyclerView.OnItemTouchListener {
private var intercept = false
override fun onTouchEvent(rv: RecyclerView, e: MotionEvent) {
}
override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
return intercept
}
setTransitionListener(object : MotionLayout.TransitionListener {
override fun onTransitionTrigger(
p0: MotionLayout?,
p1: Int,
p2: Boolean,
p3: Float
) {
}
motion.apply {
updateState(R.id.start, set)
setTransition(R.id.start, R.id.end)
transitionToEnd()
}
val set = motion.getConstraintSet(R.id.start)
set.clear(R.id.img_motion)
set.constrainWidth(R.id.img_motion, img.width)
set.constrainHeight(R.id.img_motion, img.height)
set.connect(
R.id.img_motion,
ConstraintSet.START,
ConstraintSet.PARENT_ID,
ConstraintSet.START,
rect.left
img.getLocalVisibleRect(rect)
val clipType = when {
rect.height() == img.height -> NO_CLIP
rect.top > 0 -> CLIP_TOP
else -> CLIP_BOTTOM
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/motion"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/scene_recyclerview_motion"
tools:context=".MainActivity">