Horizontalscrollview Within Scrollview Touch Handling

HorizontalScrollView within ScrollView Touch Handling

Update: I figured this out. On my ScrollView, I needed to override the onInterceptTouchEvent method to only intercept the touch event if the Y motion is > the X motion. It seems like the default behavior of a ScrollView is to intercept the touch event whenever there is ANY Y motion. So with the fix, the ScrollView will only intercept the event if the user is deliberately scrolling in the Y direction and in that case pass off the ACTION_CANCEL to the children.

Here is the code for my Scroll View class that contains the HorizontalScrollView:

public class CustomScrollView extends ScrollView {
private GestureDetector mGestureDetector;

public CustomScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
mGestureDetector = new GestureDetector(context, new YScrollDetector());
setFadingEdgeLength(0);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
}

// Return false if we're scrolling in the x direction
class YScrollDetector extends SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return Math.abs(distanceY) > Math.abs(distanceX);
}
}
}

Android: HorizontalScrollView inside ScrollView

You can use Recycler view with Staggered layout manager

 StaggeredGridLayoutManager  staggeredGridLayoutManager = new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.HORIZONTAL);

RecyclerViewAdapter recyclerViewAdapter = newRecyclerViewAdapter(this);

recyclerView.setAdapter(recyclerViewAdapter); //Don't miss to initialize your adapter

Android HorizontalScrollView disable touch handling but allow child get events

i am not very clear regarding what you want to do but, this should work,

OnTouchListener skipTouchListener = new OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {
//do nothing
return false;
}
};
yourView.setOnTouchListener(skipTouchListener);

This way yourView will not process the touch events.

Android HorizontalScrollView and Scrollview Vertical Not Working

Try this line of code

Add This line in Horizontal scroll view to solve views width problem

 <HorizontalScrollView
android:layout_width="400dp"
android:layout_height="wrap_content"
android:fillViewport="true">

android:fillViewport="true"

I have add this line in horizontal scrollview

i hope it hepls you

How to detect touch event at ScrollView?

As you've already mentioned in the question, onTouchEvent do have ACTION_UP that is meant to handle when touch up.



Related Topics



Leave a reply



Submit