国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

使用屬性動(dòng)畫實(shí)現(xiàn)一個(gè)簡(jiǎn)單的加載動(dòng)畫

2019-11-09 18:35:18
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

安卓的動(dòng)畫各種各樣,新加的屬性動(dòng)畫可以很好的實(shí)現(xiàn)動(dòng)畫效果。 如何實(shí)現(xiàn)一個(gè)簡(jiǎn)單的加載動(dòng)畫呢? 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); //顯示固定的圓,逐個(gè)出現(xiàn) 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); } //逐個(gè)消失 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); } } //移動(dòng) 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(); } }
上一篇:單例模式

下一篇:loopback 入門

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 萨迦县| 新竹市| 东辽县| 丰顺县| 嵊州市| 九江县| 佳木斯市| 常熟市| 金坛市| 汨罗市| 毕节市| 迁西县| 大新县| 藁城市| 库伦旗| 乌审旗| 新田县| 珲春市| 肃南| 贡觉县| 南岸区| 扎赉特旗| 合肥市| 社旗县| 定西市| 会宁县| 闽清县| 东兴市| 毕节市| 平度市| 平湖市| 星子县| 江门市| 彭山县| 瓮安县| 简阳市| 秀山| 班戈县| 永州市| 平塘县| 宝兴县|