From 3a139d1cd35c2bd2d1482605a2ec9313630897f5 Mon Sep 17 00:00:00 2001 From: guoziwei Date: Fri, 14 Sep 2018 10:20:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9touchlistener=20drag=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../info.txt | 0 .../listener/BarLineChartTouchListener.java | 24 ++++++++++++------- README.md | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) rename "MPChartLib/\350\257\264\346\230\216.txt" => MPChartLib/info.txt (100%) diff --git "a/MPChartLib/\350\257\264\346\230\216.txt" b/MPChartLib/info.txt similarity index 100% rename from "MPChartLib/\350\257\264\346\230\216.txt" rename to MPChartLib/info.txt diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/listener/BarLineChartTouchListener.java b/MPChartLib/src/main/java/com/github/mikephil/charting/listener/BarLineChartTouchListener.java index cbacffb..d176c1c 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/listener/BarLineChartTouchListener.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/listener/BarLineChartTouchListener.java @@ -10,6 +10,7 @@ import com.github.mikephil.charting.charts.BarLineChartBase; import com.github.mikephil.charting.charts.HorizontalBarChart; +import com.github.mikephil.charting.components.XAxis; import com.github.mikephil.charting.components.YAxis; import com.github.mikephil.charting.data.BarLineScatterCandleBubbleData; import com.github.mikephil.charting.data.Entry; @@ -295,11 +296,6 @@ private void saveTouchStart(MotionEvent event) { */ private void performDrag(MotionEvent event) { - mLastGesture = ChartGesture.DRAG; - - mMatrix.set(mSavedMatrix); - - OnChartGestureListener l = mChart.getOnChartGestureListener(); float dX, dY; @@ -319,11 +315,19 @@ private void performDrag(MotionEvent event) { dY = event.getY() - mTouchStartPoint.y; } - MPPointD point = mChart.getTransformer(YAxis.AxisDependency.LEFT).getValuesByTouchPoint(mTouchStartPoint.x, mTouchStartPoint.y); - // 如果向右滑,而且手指不在有效区域内 - if (dX < 0 && point.x > mChart.getRealCount()) { + // 如果向右滑,而且最后的坐标不在有效区域内 + XAxis xAxis = mChart.getXAxis(); + float lastX = xAxis.mEntries[xAxis.mEntryCount - 1]; + if(dX < 0 && lastX > mChart.getRealCount() - 1) { return; } + + mLastGesture = ChartGesture.DRAG; + + mMatrix.set(mSavedMatrix); + + OnChartGestureListener l = mChart.getOnChartGestureListener(); + mMatrix.postTranslate(dX, dY); if (l != null) @@ -396,12 +400,14 @@ private void performZoom(MotionEvent event) { mMatrix.set(mSavedMatrix); // 这里是自己改的 MPPointD point = mChart.getTransformer(YAxis.AxisDependency.LEFT).getValuesByTouchPoint(mTouchPointCenter.x, mTouchPointCenter.y); - if (mChart.getRealCount() > 0 && point.x > mChart.getRealCount()) { + // 手指的点不在图表的有效区域内,放大第一个 + if (point.x > mChart.getRealCount()) { mMatrix.postScale(scaleX, 1f, 0, t.y); } else { // 这里是原来的 mMatrix.postScale(scaleX, 1f, t.x, t.y); } + MPPointD.recycleInstance(point); if (l != null) l.onChartScale(event, scaleX, 1f); diff --git a/README.md b/README.md index 3239da6..e17cb08 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ android-kline是Android平台的金融图表库,包括**分时图**和**K线 } } dependencies { - compile 'com.github.VinsonGuo:android-kline:1.0.5' + compile 'com.github.VinsonGuo:android-kline:1.0.6' } ```