使用属性动画实现一个简单的加载动画
2017-02-06 17:50
525 查看
安卓的动画各种各样,新加的属性动画可以很好的实现动画效果。
如何实现一个简单的加载动画呢?
Frist of all, Because of you are custom view, you need extends the View,and implement there important method,such as onMeasure()、onDraw()、onLayout()..
Then, you need some paints to draw,so that…
and you should get the value animator, just like this!
and you should fresh your screen when your application had runing.
then,The best part of it is you need set some coding on onDraw() method to make it happen.
如何实现一个简单的加载动画呢?
Frist of all, Because of you are custom view, you need extends the View,and implement there important method,such as onMeasure()、onDraw()、onLayout()..
Then, you need some paints to draw,so that…
public FourCirlceRotate(Context context, AttributeSet attrs) { super(context, attrs); paint1 = new Paint(); paint2 = new Paint(); paint3 = new Paint(); paint4 = new Paint(); paint5 = new Paint(); paint1.setColor(Color.parseColor("#ff0099cc")); paint2.setColor(Color.parseColor("#ff669900")); paint3.setColor(Color.parseColor("#ffcc0000")); paint4.setColor(Color.parseColor("#ffaa66cc")); paint5.setColor(Color.parseColor("#ffffbb33")); }
and you should get the value animator, just like this!
private ValueAnimator getValueAnimator() { ValueAnimator valueAnimator = ValueAnimator.ofFloat(0f, 8f); valueAnimator.setDuration(4000); valueAnimator.setInterpolator(new LinearInterpolator()); valueAnimator.start(); return valueAnimator; }
and you should fresh your screen when your application had runing.
public void startAnimation() { if (valueAnimator == null) { valueAnimator = getValueAnimator(); } else { valueAnimator.start(); } R = getHeight() / 6; postDelayed(new Runnable() { @Override public void run() { if (!stop) { startAnimation(); invalidate(); } } }, valueAnimator.getDuration()); init = true; }
then,The best part of it is you need set some coding on onDraw() method to make it happen.
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // Log.i(TAG, "onDraw " + where); if (!init) { startAnimation(); } Log.e(">>>>>>>>>>>>>>>>>","show:"+show+"where:"+where); //显示固定的圆,逐个出现 if (show <= 4) { canvas.drawCircle(R, R, R, paint2); } if (show <= 3) { canvas.drawCircle(getWidth() - R, R, R, paint3); } if (show <= 2) { canvas.drawCircle(getWidth() - R, getHeight() - R, R, paint4); } if (show <= 1) { canvas.drawCircle(R, getHeight() - R, R, paint5); } //逐个消失 if (show > 4) { if (show <= 4) { canvas.drawCircle(R, R, R, paint2); } if (show <= 5) { canvas.drawCircle(getWidth() - R, R, R, paint3); } if (show <= 6) { canvas.drawCircle(getWidth() - R, getHeight() - R, R, paint4); } if (show <= 7) { canvas.drawCircle(R, getHeight() - R, R, paint5); } } //移动 if (where < 1 && where > 0) { canvas.drawCircle(R + (getWidth() - 2 * R) * where, R, R, paint1); show = 4; } if (where < 2 && where > 1) { canvas.drawCircle(getHeight() - R, R + (getHeight() - 2 * R) * (where - 1), R, paint1); show = 3; } if (where < 3 && where > 2) { canvas.drawCircle(getWidth() - R - (getWidth() - 2 * R) * (where - 2), getHeight() - R, R, paint1); show = 2; } if (where < 4 && where > 3) { canvas.drawCircle(R, getHeight() - R - (getHeight() - 2 * R) * (where - 3), R, paint1); show = 1; } if (where > 4 && where < 5) { canvas.drawCircle(R + (getWidth() - 2 * R) * (where - 4), R, R, paint1); show = 5; } if (where > 5 && where < 6) { canvas.drawCircle(getHeight() - R, R + (getHeight() - 2 * R) * (where - 5), R, paint1); show = 6; } if (where > 6 && where < 7) { canvas.drawCircle(getWidth() - R - (getWidth() - 2 * R) * (where - 6), getHeight() - R, R, paint1); show = 7; } if (where > 7 && where < 8) { canvas.drawCircle(R, getHeight() - R - (getHeight() - 2 * R) * (where - 7), R, paint1); show = 8; } if (isStart) { where = (float) valueAnimator.getAnimatedValue(); } if (valueAnimator.isRunning()) { isStart = true; invalidate(); } }
相关文章推荐
- 使用Unity实现一个简单的UV动画
- 一个简单的加载动画,js实现
- 浅谈属性动画简单使用之实现卫星菜单(二)
- 绘图与动画之使用自定义属性与Quartz实现扇形加载动画
- Swift实现一个简单的加载动画,以及动画的详解
- Android 属性动画实现一个简单的PopupWindow
- 浅谈属性动画简单使用之实现爱的贝塞尔曲线浪漫告白效果(三)
- 加载动图的实现及属性动画的使用
- 浅谈属性动画简单使用之实现卫星菜单(二)
- 浅谈属性动画简单使用之实现爱的贝塞尔曲线浪漫告白效果(三)
- 绘图与动画之使用自定义属性与颜色渐变实现色带加载动画
- cocos2d中如何使用图片纹理图集的加载来实现一个动画的功能
- 【iOS开展-50】使用它来创建一个新的类的实现代码包,因此,不自觉地练习简单MVC实验,附带动画
- 利用JAVA的动态属性之反射原理实现一个简单AOP容器 - AOP的实现原理分析
- 使用Node.js + MongoDB实现一个简单的日志分析系统
- Thrift使用入门(2) - 用Thrift实现一个简单的Server/Client应用程序
- 用最简单的函数实现功能:判断一个int数据是否是2的x次幂(不能使用循环)。
- 用Python 实现刷钻网上抢任务,并实现一个简单的限制使用时间的功能
- 使用NSTimer与iphone的简单动画,实现飘雪效果
- Ajax 之使用 XMLHttp实现简单的异步数据加载