1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

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

        共 2412字,需瀏覽 5分鐘

         ·

        2021-08-27 19:33

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



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



        先看下概念圖


        ●音符動(dòng)畫


        音符動(dòng)畫這里是利用貝塞爾曲線

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



        1、貝塞爾曲線的繪制:因?yàn)橐舴倪\(yùn)動(dòng)軌跡是自下而上的,因此我們在添加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)動(dòng)

        private void initPath() {    //新建兩個(gè)float數(shù)組pos用來存儲(chǔ)每個(gè)軌跡點(diǎn)的坐標(biāo),tan用來存儲(chǔ)正切值    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í)行動(dòng)畫    valueAnimator.setRepeatCount(ValueAnimator.INFINITE);    //設(shè)置為勻速運(yùn)動(dòng)    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)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            午夜免费爱爱视频 | 色五月婷婷色五月 | 久久天天躁狠狠躁夜夜96流白浆 | 日韩电影久久 | 一区二区三区四区视频精品免费 | 男女一进一出动态图 | 大吊无码 | 亚洲图色色 | 久久综合88 | 日韩精品中文字幕视频 |