<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Android仿抖音音樂旋轉(zhuǎn)效果

          共 2412字,需瀏覽 5分鐘

           ·

          2021-08-27 19:33

          這次是實(shí)現(xiàn)一個(gè)仿抖音的音樂旋轉(zhuǎn)自定義View,先看一下效果:



          實(shí)現(xiàn)這個(gè)效果主要是采用的拼湊的方法,即先實(shí)現(xiàn)音符動畫再實(shí)現(xiàn)圖片旋轉(zhuǎn)動畫然后將兩個(gè)效果合并到一起。



          先看下概念圖


          ●音符動畫


          音符動畫這里是利用貝塞爾曲線

          +PathMeasure+ValueAnimator來實(shí)現(xiàn)的



          1、貝塞爾曲線的繪制:因?yàn)橐舴倪\(yùn)動軌跡是自下而上的,因此我們在添加Path路徑的時(shí)候需要先將起點(diǎn)移到右下角,然后再繪制貝塞爾曲線。

          path = new Path();//將起點(diǎn)移到右下角path.moveTo(getWidth(),getHeight()-getWidth()/6);//繪制自下而上的貝塞爾曲線path.quadTo(0,getHeight(),getWidth()/4,0);



          2、PathMeasure+ValueAnimator實(shí)現(xiàn)音符沿軌跡運(yùn)動

          private void initPath() {    //新建兩個(gè)float數(shù)組pos用來存儲每個(gè)軌跡點(diǎn)的坐標(biāo),tan用來存儲正切值    pos = new float[2];    tan = new float[2];    path = new Path();    path.moveTo(getWidth(),getHeight()-getWidth()/6);    path.quadTo(0,getHeight(),getWidth()/4,0);    pathMeasure = new PathMeasure(path,false);    length = pathMeasure.getLength();    valueAnimator = ValueAnimator.ofFloat(0,2f);    valueAnimator.setDuration(3000);    //設(shè)置重復(fù)執(zhí)行動畫    valueAnimator.setRepeatCount(ValueAnimator.INFINITE);    //設(shè)置為勻速運(yùn)動    valueAnimator.setInterpolator(new LinearInterpolator());    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {        @Override        public void onAnimationUpdate(ValueAnimator animation) {            float temp=(float) animation.getAnimatedValue();            val= temp/2;            //這里實(shí)現(xiàn)音符的透明度從0~1~0的效果            if(temp>1){                Music3.this.setAlpha(Math.abs(temp-2f));            }else {                Music3.this.setAlpha(temp);            }            //更新界面            invalidate();        }    });    valueAnimator.start();}@Overrideprotected void onDraw(Canvas canvas) {    super.onDraw(canvas);    //獲取每個(gè)點(diǎn)對應(yīng)的坐標(biāo)    pathMeasure.getPosTan(length*val,pos,tan);    //創(chuàng)建音符BitMap寬高是逐漸放大的    scaledBitmap = Bitmap.createScaledBitmap(bitmap, (int)(getWidth()/5*val)+4, (int)(getWidth()/5*val)+4, true);    canvas.drawPath(path,paint);    canvas.drawBitmap(scaledBitmap,pos[0],pos[1],paint);}



          ●圖片旋轉(zhuǎn)


          這里我引用的一個(gè)第三方的圓形圖片庫

          implementation 'de.hdodenhof:circleimageview:2.2.0'


          實(shí)現(xiàn)圖片旋轉(zhuǎn)

          circleImageView = findViewById(R.id.mm);RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);rotateAnimation.setInterpolator(new LinearInterpolator());rotateAnimation.setDuration(4000);rotateAnimation.setRepeatCount(Animation.INFINITE);circleImageView.startAnimation(rotateAnimation);



          源碼地址:
          https://gitee.com/itfittnesss/DouYinMusic


          到這里就結(jié)束啦。
          瀏覽 80
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  精品人妻一区二区三区在 | 国产欧美日韩视频在线观看 | 国产A片视频 | 天天日天天干成人影音 | 久久成人三级电影 |