Skip to content

Instantly share code, notes, and snippets.

@mrenouf
Created February 9, 2018 19:19
Show Gist options
  • Save mrenouf/33ffe69f79f0c8d91e1ffd028dd46985 to your computer and use it in GitHub Desktop.
Save mrenouf/33ffe69f79f0c8d91e1ffd028dd46985 to your computer and use it in GitHub Desktop.
NonGreedyNestedScrollView
package com.example.mrenouf.touchtest;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.widget.NestedScrollView;
import android.util.AttributeSet;
import android.view.MotionEvent;
public class NonGreedyNestedScrollView extends NestedScrollView {
public NonGreedyNestedScrollView(@NonNull Context context) {
this(context, null, 0);
}
public NonGreedyNestedScrollView(@NonNull Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public NonGreedyNestedScrollView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN
&& !ViewGroups.isTopChildUnder(this, event.getX(), event.getY())) {
return false;
}
return super.onInterceptTouchEvent(event);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN
&& !ViewGroups.isTopChildUnder(this, event.getX(), event.getY())) {
return false;
}
return super.onTouchEvent(event);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment