最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android使用自定義view在指定時間內(nèi)勻速畫一條直線的實(shí)例代碼

 更新時間:2018年05月15日 10:59:18   投稿:yanan  
這篇文章主要介紹了Android使用自定義view在指定時間內(nèi)勻速畫一條直線的實(shí)例代碼,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

本文講述了Android使用自定義view在指定時間內(nèi)勻速畫一條直線的實(shí)例代碼。分享給大家供大家參考,具體如下:

1.效果圖:

2.自定義view實(shí)現(xiàn)

public class UniformLine extends View { 
 private int x, y, nextX, nextY, incrementY, incrementX; 
 public UniformLine(Context context) { 
 super(context); 
 } 
 public UniformLine(Context context, int x, int y, int nextX, int nextY) { 
 super(context); 
 this.x = x; 
 this.y = y; 
 this.nextX = nextX; 
 this.nextY = nextY; 
 init(); 
 } 
 private void init() { 
 p = new Paint(); 
 p.setColor(Color.WHITE); 
 p.setAntiAlias(true); 
 p.setStrokeWidth(4.0f); 
 
 ValueAnimator valueAnimatorX = ValueAnimator.ofFloat(x, nextX); 
 valueAnimatorX.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 
  @Override 
  public void onAnimationUpdate(ValueAnimator animation) { 
  incrementX = Math.round((Float) animation.getAnimatedValue()); 
  invalidate(); 
  } 
 }); 
 ValueAnimator valueAnimatorY = ValueAnimator.ofInt(y, nextY); 
 valueAnimatorY.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 
  @Override 
  public void onAnimationUpdate(ValueAnimator animation) { 
  incrementY = (int) animation.getAnimatedValue(); 
  invalidate(); 
  } 
 }); 
 AnimatorSet animatorSet = new AnimatorSet(); 
 LinearInterpolator ll = new LinearInterpolator(); 
 animatorSet.setInterpolator(ll);//勻速 
 animatorSet.setDuration(2000); 
 animatorSet.playTogether(valueAnimatorX, valueAnimatorY); 
 animatorSet.start(); 
 } 
 Paint p; 
 @Override 
 protected void onDraw(Canvas canvas) { 
 super.onDraw(canvas); 
 canvas.drawLine(Util.Div(Math.round(x)), Util.Div(Math.round(y)), 
  Util.Div(Math.round(incrementX)), Util.Div(Math.round(incrementY)), p);// 斜線 
 } 
} 

3.調(diào)用

uniformLine = new UniformLine(mContext, 300, 500, 600, 200); 
addView(uniformLine); 

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

最新評論

车致| 民勤县| 白朗县| 墨江| 抚顺市| 沙湾县| 岑巩县| 彭水| 明水县| 科技| 井研县| 长宁县| 游戏| 高淳县| 迁西县| 正镶白旗| 合阳县| 东源县| 中宁县| 商城县| 花莲市| 玉山县| 无极县| 女性| 长丰县| 百色市| 邛崃市| 广饶县| 大石桥市| 上杭县| 皋兰县| 石屏县| 涟水县| 卢湾区| 麦盖提县| 侯马市| 揭阳市| 梧州市| 铅山县| 华池县| 青川县|