2024年安卓最新MPAndroidChart 教程:动画 Animations(十)(1),2024年最新金三银四我带你去BAT面试现场

最后笔者收集整理了一份Flutter高级入门进阶资料PDF

以下是资料目录和内容部分截图



里面包括详细的知识点讲解分析,带你一个星期入门Flutter。还有130个进阶学习项目实战视频教程,让你秒变大前端。

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

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

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

// 设置动画

chart.animateX(8000); // 图1

chart.animateY(8000); // 图2

chart.animateXY(8000, 8000); // 图3

chart.animateY(8000, Easing.EasingOption.EaseInElastic ); // 图4

2) BarChart 效果图

// 设置动画

chart.animateX(8000); // 图1

chart.animateY(8000); // 图2

chart.animateXY(8000, 8000); // 图3

chart.animateY(8000, Easing.EasingOption.EaseInSine); // 图4

3) PieChart 效果图

// 设置动画

chart.animateX(8000); // 图1

chart.animateY(8000); // 图2

chart.animateXY(8000,8000); // 图3

chart.animateY(8000, Easing.EasingOption.EaseOutBounce); // 图4

二、概述


MPAndroidChart 的动画机制只在Android API 11 (Android 3.0.x) 和以上有效。

在低于 Android 3.0.x 的版本中动画不会执行(但不会引起 crash)。

所有图表类型都支持动画,可以用来创建/建立图表在一个很棒的方法。三种不同的动画方法存在,动画,或者x轴和y轴分别:

  • animateX(int durationMillis) : 水平轴的图表值动画,这意味着在指定的时间内从左到右 建立图表

  • animateY(int durationMillis) : 垂直轴的图表值动画,这意味着在指定的时间内从下到上 建立图表

  • animateXY(int xDuration, int yDuration) : 两个轴的图表值动画,从左到右,从下到上 建立图表

mChart.animateX(3000); // animate horizontal 3000 milliseconds

// or:

mChart.animateY(3000); // animate vertical 3000 milliseconds

// or:

mChart.animateXY(3000, 3000); // animate horizontal and vertical 3000 milliseconds

任意一种 animate(...) 动画方法被调用后,无需再调用 invalidate() 方法。

三、ChartAnimator 动画源码分析


/**

  • Object responsible for all animations in the Chart. ANIMATIONS ONLY WORK FOR

  • API LEVEL 11 (Android 3.0.x) AND HIGHER.

*/

@SuppressLint(“NewApi”)

public class ChartAnimator {

/** object that is updated upon animation update */

private AnimatorUpdateListener mListener;

public ChartAnimator() {}

public ChartAnimator(AnimatorUpdateListener listener) {

mListener = listener;

}

/** the phase that is animated and influences the drawn values on the y-axis */

protected float mPhaseY = 1f;

/** the phase that is animated and influences the drawn values on the x-axis */

protected float mPhaseX = 1f;

// 下面的动画方法

}

1) animateX( … ) 方法的源码

/**

  • Animates the rendering of the chart on the x-axis with the specified

  • animation time. If animate(…) is called, no further calling of

  • invalidate() is necessary to refresh the chart.

  • @param durationMillis

*/

public void animateX(int durationMillis) {

if (android.os.Build.VERSION.SDK_INT < 11)

return;

ObjectAnimator animatorX = ObjectAnimator.ofFloat(this, “phaseX”, 0f, 1f);

animatorX.setDuration(durationMillis);

animatorX.addUpdateListener(mListener);

animatorX.start();

}

public void animateX(int durationMillis, Easing.EasingOption easing) {

if (android.os.Build.VERSION.SDK_INT < 11)

return;

ObjectAnimator animatorX = ObjectAnimator.ofFloat(this, “phaseX”, 0f, 1f);

animatorX.setInterpolator(Easing.getEasingFunctionFromOption(easing));

animatorX.setDuration(durationMillis);

animatorX.addUpdateListener(mListener);

animatorX.start();

}

public void animateX(int durationMillis, EasingFunction easing) {

if (android.os.Build.VERSION.SDK_INT < 11)

return;

ObjectAnimator animatorX = ObjectAnimator.ofFloat(this, “phaseX”, 0f, 1f);

animatorX.setInterpolator(easing);

animatorX.setDuration(durationMillis);

animatorX.addUpdateListener(mListener);

animatorX.start();

}

2) animateY( … ) 方法的源码

/**

  • Animates the rendering of the chart on the y-axis with the specified

  • animation time. If animate(…) is called, no further calling of

  • invalidate() is necessary to refresh the chart.

  • @param durationMillis

*/

public void animateY(int durationMillis) {

if (android.os.Build.VERSION.SDK_INT < 11)

return;

ObjectAnimator animatorY = ObjectAnimator.ofFloat(this, “phaseY”, 0f, 1f);

animatorY.setDuration(durationMillis);

animatorY.addUpdateListener(mListener);

animatorY.start();

}

public void animateY(int durationMillis, Easing.EasingOption easing) {

if (android.os.Build.VERSION.SDK_INT < 11)

return;

ObjectAnimator animatorY = ObjectAnimator.ofFloat(this, “phaseY”, 0f, 1f);

animatorY.setInterpolator(Easing.getEasingFunctionFromOption(easing));

animatorY.setDuration(durationMillis);

animatorY.addUpdateListener(mListener);

animatorY.start();

}

public void animateY(int durationMillis, EasingFunction easing) {

if (android.os.Build.VERSION.SDK_INT < 11)

return;

ObjectAnimator animatorY = ObjectAnimator.ofFloat(this, “phaseY”, 0f, 1f);

animatorY.setInterpolator(easing);

animatorY.setDuration(durationMillis);

animatorY.addUpdateListener(mListener);

animatorY.start();

}

3) animateXY( … ) 方法的源码

/**

  • Animates the drawing / rendering of the chart on both x- and y-axis with

  • the specified animation time. If animate(…) is called, no further

  • calling of invalidate() is necessary to refresh the chart.

  • @param durationMillisX

  • @param durationMillisY

*/

public void animateXY(int durationMillisX, int durationMillisY) {

if (android.os.Build.VERSION.SDK_INT < 11)

return;

ObjectAnimator animatorY = ObjectAnimator.ofFloat(this, “phaseY”, 0f, 1f);

animatorY.setDuration(

durationMillisY);

ObjectAnimator animatorX = ObjectAnimator.ofFloat(this, “phaseX”, 0f, 1f);

animatorX.setDuration(

durationMillisX);

// make sure only one animator produces update-callbacks (which then

// call invalidate())

if (durationMillisX > durationMillisY) {

animatorX.addUpdateListener(mListener);

} else {

animatorY.addUpdateListener(mListener);

}

animatorX.start();

animatorY.start();

}

public void animateXY(int durationMillisX, int durationMillisY, Easing.EasingOption easingX,

Easing.EasingOption easingY) {

if (android.os.Build.VERSION.SDK_INT < 11)

return;

ObjectAnimator animatorY = ObjectAnimator.ofFloat(this, “phaseY”, 0f, 1f);

animatorY.setInterpolator(Easing.getEasingFunctionFromOption(easingY));

animatorY.setDuration(

durationMillisY);

ObjectAnimator animatorX = ObjectAnimator.ofFloat(this, “phaseX”, 0f, 1f);

animatorX.setInterpolator(Easing.getEasingFunctionFromOption(easingX));

animatorX.setDuration(

durationMillisX);

// make sure only one animator produces update-callbacks (which then

// call invalidate())

if (durationMillisX > durationMillisY) {

animatorX.addUpdateListener(mListener);

} else {

animatorY.addUpdateListener(mListener);

}

animatorX.start();

animatorY.start();

}

public void animateXY(int durationMillisX, int durationMillisY, EasingFunction easingX,

EasingFunction easingY) {

if (android.os.Build.VERSION.SDK_INT < 11)

return;

ObjectAnimator animatorY = ObjectAnimator.ofFloat(this, “phaseY”, 0f, 1f);

animatorY.setInterpolator(easingY);

animatorY.setDuration(

durationMillisY);

ObjectAnimator animatorX = ObjectAnimator.ofFloat(this, “phaseX”, 0f, 1f);

animatorX.setInterpolator(easingX);

animatorX.setDuration(

durationMillisX);

// make sure only one animator produces update-callbacks (which then

// call invalidate())

if (durationMillisX > durationMillisY) {

animatorX.addUpdateListener(mListener);

} else {

animatorY.addUpdateListener(mListener);

最后为了帮助大家深刻理解Android相关知识点的原理以及面试相关知识,这里放上相关的我搜集整理的24套腾讯、字节跳动、阿里、百度2020-2021面试真题解析,我把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包知识脉络 + 诸多细节

还有 高级架构技术进阶脑图、Android开发面试专题资料 帮助大家学习提升进阶,也节省大家在网上搜索资料的时间来学习,也可以分享给身边好友一起学习。

一线互联网面试专题

379页的Android进阶知识大全

379页的Android进阶知识大全

网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。希望这份系统化的技术体系对大家有一个方向参考。

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

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

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

识脉络 + 诸多细节**。

还有 高级架构技术进阶脑图、Android开发面试专题资料 帮助大家学习提升进阶,也节省大家在网上搜索资料的时间来学习,也可以分享给身边好友一起学习。

[外链图片转存中…(img-Pv0JYNvh-1715817293385)]

[外链图片转存中…(img-HCQs9Vlk-1715817293385)]

[外链图片转存中…(img-xRWIkDaW-1715817293386)]

网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。希望这份系统化的技术体系对大家有一个方向参考。

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

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值