0

I have a recyclerview which scrolls horizontally and a line mpchart that scrolls horizontally too(these are seperate of each other). I want to scroll them simultaneously. Can anyone help me please?

razi
  • 77
  • 8
  • This sounds like managing a nested scroll view problem and is probably already answered. Check if the answer here would help you: https://stackoverflow.com/questions/48477033/scrollview-inside-recyclerview-wont-scroll or search for something like "scroll view inside a recylcerview" – kidroca Dec 23 '20 at 15:46

1 Answers1

0

I finally solved the problem by using these codes

     recyclerView.setOnScrollChangeListener(new RecyclerView.OnScrollChangeListener() 
       {
        @Override
        public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, 
       int oldScrollY) {
            lineChart.scrollBy(scrollX - oldScrollX, scrollY - oldScrollY);          
            lineChart.notifyDataSetChanged();
            lineChart.invalidate();

        }
    });
    lineChart.setOnChartGestureListener(new OnChartGestureListener() {
        @Override
        public void onChartGestureStart(MotionEvent me, 
  ChartTouchListener.ChartGesture lastPerformedGesture) {
        }

        @Override
        public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture 
      lastPerformedGesture) {

        }

        @Override
        public void onChartLongPressed(MotionEvent me) {

        }

        @Override
        public void onChartDoubleTapped(MotionEvent me) {

        }

        @Override
        public void onChartSingleTapped(MotionEvent me) {

        }

        @Override
        public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {

        }

        @Override
        public void onChartScale(MotionEvent me, float scaleX, float scaleY) {

        }

        @Override
        public void onChartTranslate(MotionEvent me, float dX, float dY) {
           recyclerView.scrollBy((int) -dX, (int) -dY);
            lineChart.notifyDataSetChanged();
            lineChart.invalidate();
        }
    });

now everything works well. the only problem is that my chart scrolles behind it's parent

razi
  • 77
  • 8