MPAndroidChart 教程:与图表进行手势交互 Interaction with the Chart(二)

最后我还整理了很多Android中高级的PDF技术文档。以及一些大厂面试真题解析文档。

image

Android高级架构师之路很漫长,一起共勉吧!

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • Callbacks when a touch-gesture has started on the chart (ACTION_DOWN)

  • @param me

  • @param lastPerformedGesture

*/

void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture);

/**

  • Callbacks when a touch-gesture has ended on the chart (ACTION_UP, ACTION_CANCEL)

  • @param me

  • @param lastPerformedGesture

*/

void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture);

/**

  • Callbacks when the chart is longpressed.

  • @param me

*/

public void onChartLongPressed(MotionEvent me);

/**

  • Callbacks when the chart is double-tapped.

  • @param me

*/

public void onChartDoubleTapped(MotionEvent me);

/**

  • Callbacks when the chart is single-tapped.

  • @param me

*/

public void onChartSingleTapped(MotionEvent me);

/**

  • Callbacks then a fling gesture is made on the chart.

  • @param me1

  • @param me2

  • @param velocityX

  • @param velocityY

*/

public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY);

/**

  • Callbacks when the chart is scaled / zoomed via pinch zoom gesture.

  • @param me

  • @param scaleX scalefactor on the x-axis

  • @param scaleY scalefactor on the y-axis

*/

public void onChartScale(MotionEvent me, float scaleX, float scaleY);

/**

  • Callbacks when the chart is moved / translated via drag gesture.

  • @param me

  • @param dX translation distance on the x-axis

  • @param dY translation distance on the y-axis

*/

public void onChartTranslate(MotionEvent me, float dX, float dY);

}

让你的类实现该接口并设置对 chart 进行监听,即可接受回调。

chart.setOnChartGestureListener(this);

设置了监听器后,chart 会根据你的 setXXXEnable() 进行放缩移动等操作。不用在接口方法里对图表进行放缩移动等其他操作,接口方法可以让你实现其他对应功能,比如说你要打印放缩是的 ScaleX,ScaleY :

@Override

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

Log.i(“Scale / Zoom”, "ScaleX: " + scaleX + ", ScaleY: " + scaleY);

}

打印的日志类似:

I/Gesture: START

I/Scale / Zoom: ScaleX: 1.0, ScaleY: 1.0

I/Scale / Zoom: ScaleX: 1.0, ScaleY: 1.0

I/Scale / Zoom: ScaleX: 1.0174584, ScaleY: 1.0174584

I/Scale / Zoom: ScaleX: 1.240304, ScaleY: 1.240304

I/Scale / Zoom: ScaleX: 1.4446417, ScaleY: 1.4446417

I/Scale / Zoom: ScaleX: 1.5617653, ScaleY: 1.5617653

I/Scale / Zoom: ScaleX: 1.0241176, ScaleY: 1.0241176

I/Scale / Zoom: ScaleX: 1.1038365, ScaleY: 1.1038365

I/Gesture: END, lastGesture: PINCH_ZOOM

下面是练习时写的一些 OnChartGestureListener 接口实现方法:

@Override

public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {

Log.i(“Gesture”, “START”);

}

@Override

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

Log.i(“Gesture”, "END, lastGesture: " + lastPerformedGesture);

// un-highlight values after the gesture is finished and no single-tap

if (lastPerformedGesture != ChartTouchListener.ChartGesture.SINGLE_TAP)

mChart.highlightValues(null); // or highlightTouch(null) for callback to onNothingSelected(…)

}

@Override

public void onChartLongPressed(MotionEvent me) {

Log.i(“LongPress”, “Chart longpressed.”);

}

@Override

public void onChartDoubleTapped(MotionEvent me) {

Log.i(“DoubleTap”, “Chart double-tapped.”);

}

@Override

public void onChartSingleTapped(MotionEvent me) {

Log.i(“SingleTap”, “Chart single-tapped.”);

}

@Override

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

Log.i(“Fling”, "Chart flinged. VeloX: " + velocityX + ", VeloY: " + velocityY);

}

@Override

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

Log.i(“Scale / Zoom”, "ScaleX: " + scaleX + ", ScaleY: " + scaleY);

}

@Override

public void onChartTranslate(MotionEvent me, float dX, float dY) {

Log.i(“Translate / Move”, "dX: " + dX + ", dY: " + dY);

}

@Override

public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {

Log.i(“Entry selected”, e.toString());

Log.i(“”, "low: " + mChart.getLowestVisibleXIndex() + ", high: " + mChart.getHighestVisibleXIndex());

总结:

各行各样都会淘汰一些能力差的,不仅仅是IT这个行业,所以,不要被程序猿是吃青春饭等等这类话题所吓倒,也不要觉得,找到一份工作,就享受安逸的生活,你在安逸的同时,别人正在奋力的向前跑,这样与别人的差距也就会越来越遥远,加油,希望,我们每一个人,成为更好的自己。

  • BAT大厂面试题、独家面试工具包,

  • 资料包括 数据结构、Kotlin、计算机网络、Framework源码、数据结构与算法、小程序、NDK、Flutter,


网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

[外链图片转存中…(img-fHby656V-1715268313471)]
[外链图片转存中…(img-vnHoeBsb-1715268313471)]

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值