I have a LineChart contained within a ScrollView. When the chart is long enough for it to be necessary for a user to scroll to see it in its entirety, the drag features become unresponsive. Drag gestures only register when I hold my finger down for a short period of time in the chart bounds and then drag.
I have tried using the requestDisallowInterceptTouchEvent method that should prevent the chart's parents from intercepting the touch events (but this doesn't solve anything). I've also tried directly passing MotionEvents registered by the ScrollView straight to the chart/translating drag gestures to translateY calls but this doesn't do what I thought it would.
Note: Zooming continues to work perfectly.
Also, this is not an issue when the graph fits in the original window or when it's placed in any view that is not a ScrollView. I have considered getting rid of the ScrollView but it's a pretty necessary feature in my project.
Any ideas on why this could be happening would be appreciated!
Edit: the LineChart has a fixed height
This question is kind of old but I run into the same problem recently and to solve it, I did the following.
ex.
clickInterceptorGraph.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return onTouchActionHandler(v, event);
}
});
ex.
protected boolean onTouchActionHandler(View v, MotionEvent event){
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow RecyclerView to intercept touch events.
scrollView.requestDisallowInterceptTouchEvent(true);
Log.e(TAG, "onTouchActionHandler: ACTION_DOWN" );
// Disable touch on transparent view
return false;
default:
return true;
}
}
*** You could do everything on the setOntouchListener but in my case I need to reuse the requestDisallowInterceptTouchEvent.
Similar approach as Ruan_Lopes mentioned, you just don't need a transparent overlay view. You can also use chart gesture listener to intercept touches the same way.
lineChart.onChartGestureListener = object : OnChartGestureListener {
override fun onChartGestureEnd(
me: MotionEvent?,
lastPerformedGesture: ChartTouchListener.ChartGesture?
) = Unit
override fun onChartFling(
me1: MotionEvent?,
me2: MotionEvent?,
velocityX: Float,
velocityY: Float
) = Unit
override fun onChartSingleTapped(me: MotionEvent?) = Unit
override fun onChartGestureStart(
e: MotionEvent?,
lastPerformedGesture: ChartTouchListener.ChartGesture?
) = recyclerView.requestDisallowInterceptTouchEvent(true)
override fun onChartScale(me: MotionEvent?, scaleX: Float, scaleY: Float) = Unit
override fun onChartLongPressed(me: MotionEvent?) = Unit
override fun onChartDoubleTapped(me: MotionEvent?) = Unit
override fun onChartTranslate(me: MotionEvent?, dX: Float, dY: Float) = Unit
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With