【问题标题】:Switching between HorizontalScrollView and BarChart scroll在 Horizo​​ntalScrollView 和 BarChart 滚动之间切换
【发布时间】:2019-11-28 09:55:37
【问题描述】:

我有一个放置在 Horizo​​ntalScrollView 内的 MPAndroidChart BarChart。现在,我在图表视图中有多个条形图,并且图表宽度根据我的要求是固定的。由于图表有默认的滚动行为,我可以看到所有的条形图。

唯一的问题是滚动行为不流畅并且滞后很多。

我的想法是在我开始滚动图表后禁用 Horizo​​ntalScrollView,并在我触摸图表外部时重新启用它。有人可以告诉我我该怎么做吗?我希望我的问题足够清楚,不需要为此共享任何 XML。提前致谢。

【问题讨论】:

    标签: java android mpandroidchart horizontalscrollview


    【解决方案1】:

    我在水平滚动视图中使用 Mpchart 时遇到了类似的问题。 我有一个使用 MpChart setOnChartGestureListener 的解决方法。

    barChart.setOnChartGestureListener(new OnChartGestureListener() {
            @Override
            public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
                horizontalScrollView.requestDisallowInterceptTouchEvent(true);
            }
    
            @Override
            public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
                horizontalScrollView.requestDisallowInterceptTouchEvent(false);
            }
    
            //.....//
    
            @Override
            public void onChartTranslate(MotionEvent me, float dX, float dY) {
                Log.i("GESTURE", "onChartTranslate");
                if(barChart.getLowestVisibleX() == barChart.getXAxis().getAxisMinimum() || barChart.getHighestVisibleX() == barChart.getXAxis().getAxisMaximum()) {
                    horizontalScrollView.requestDisallowInterceptTouchEvent(false);
                } else {
                    horizontalScrollView.requestDisallowInterceptTouchEvent(true);
                }
            }
        });
    

    horizo​​ntalScrollView 对象是图表所在的位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多