I am using a MotionLayout with a scene-xml:
<
@muetzenflo's response is the most efficient solution I've seen so far for this problem.
However, only checking the Event.Action
for MotionEvent.ACTION_MOVE
causes the MotionLayout
to respond poorly. It is better to differentiate between movement and a single click by the use of ViewConfiguration.TapTimeout
as the example below demonstrates.
public class MotionSubLayout extends MotionLayout {
private long mStartTime = 0;
public MotionSubLayout(@NonNull Context context) {
super(context);
}
public MotionSubLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public MotionSubLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if ( event.getAction() == MotionEvent.ACTION_DOWN ) {
mStartTime = event.getEventTime();
} else if ( event.getAction() == MotionEvent.ACTION_UP ) {
if ( event.getEventTime() - mStartTime <= ViewConfiguration.getTapTimeout() ) {
return false;
}
}
return super.onInterceptTouchEvent(event);
}
}