constraintlayout
constraintlayout copied to clipboard
when setOnClickListener on views in motionlayout it can't be drag.
when setOnClickListener on views in motionlayout it can't be drag. it seems MotionEvent.ACTION_MOVE event being ignore on the views.
Try the flag in the transition motion:transitionFlags="onInterceptTouchReturnSwipe"
which version of motionlayout have this selection? in my motionlayout 2.1.0 , motion:transitionFlags just have "disableIntraAutoTransition" or "beginOnFirstDraw" or "none"
motion:transitionFlags="beginOnFirstDraw"
motion:motionInterpolator="linear"
2.1.3
it not works , i tested the official demo , link is here
when i add the underlying codes to DemoActivity.kt , the picture can't drag. Is there any other way to add click event in motionlayout by code ?
if (layout == R.layout.motion_05_imagefilter) {
findViewById<ImageFilterView>(R.id.image).setOnClickListener {
Toast.makeText(this, "show toast", Toast.LENGTH_LONG).show()
}
}
hello, Is there any progress?
finally, when MotionEvent is moving, it shouldn't allow children view to consume the event, so. i intercept the motion event as underlying code in a custom motionlayout . it works now.
private var touchDownX = 0f
private var touchDownY = 0f
private var mScrolling = false
private val touchSlop = ViewConfiguration.get(context).scaledTouchSlop
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
when (event.action) {
MotionEvent.ACTION_DOWN -> {
touchDownX = event.x
touchDownY = event.y
mScrolling = false
}
MotionEvent.ACTION_MOVE -> mScrolling = abs(touchDownY - event.y) >= touchSlop
MotionEvent.ACTION_UP -> mScrolling = false
}
return if (mScrolling) true else super.onInterceptTouchEvent(event)
}
@showwiki Thank you. Worked for me. Here is a full implementation in Kotlin:
class ClickFriendlyMotionLayout @JvmOverloads constructor(
context: Context,
attributeSet: AttributeSet? = null,
defStyleAttr: Int = 0
): MotionLayout(context, attributeSet, defStyleAttr) {
private var touchDownX = 0f
private var touchDownY = 0f
private var mScrolling = false
private val touchSlop = ViewConfiguration.get(context).scaledTouchSlop
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
when (event.action) {
MotionEvent.ACTION_DOWN -> {
touchDownX = event.x
touchDownY = event.y
mScrolling = false
}
MotionEvent.ACTION_MOVE -> mScrolling = abs(touchDownY - event.y) >= touchSlop
MotionEvent.ACTION_UP -> mScrolling = false
}
return if (mScrolling) true else super.onInterceptTouchEvent(event)
}
}
Unfortunately, this fix, brakes scrolling in the recycler view/view pager.
Upon further investigation and testing, we have come to the realization that the proposed fix for the issue at hand unfortunately results in an unintended and undesirable consequence. Specifically, it has been observed that the scrolling functionality within the recycler view or view pager is now broken due to the implementation of the fix.
@isamotiuc @DanieleRigo did you guys find any solution for the recyclerview scrolling? Thanks