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
How to Make an Android Spinner With Initial Text "Select One"
Environment.Getexternalstoragedirectory() Deprecated in API Level 29 Java
Getapplication() Vs. Getapplicationcontext()
How to Assign an Id to a View Programmatically
Install_Failed_No_Matching_Abis When Install Apk
Android Soft Keyboard Covers Edittext Field
Failed to Resolve: Com.Android.Support:Appcompat-V7:26.0.0
How to Remove All Debug Logging Calls Before Building the Release Version of an Android App
Get Screen Width and Height in Android
Sharedpreferences.Onsharedpreferencechangelistener Not Being Called Consistently
How to Read Contacts on Android 2.0
How to Implement Onfragmentinteractionlistener
Background Task, Progress Dialog, Orientation Change - Is There Any 100% Working Solution
This Handler Class Should Be Static or Leaks Might Occur: Incominghandler
Android "Only the Original Thread That Created a View Hierarchy Can Touch Its Views."