Music rotation vibrato effect imitation of the advanced Android

Thermal paper REVIEW |   Click on the title to read

Under Internet winter, the programmer how to break through to enhance their own?

Performance evaluation and optimization android - Memory

Naked resignation two months, the sea cast month, moved from the Web front-end Android job search road

Original: https: //myml666.github.io ( source code download see the end of the article )
 
  

This is to achieve a vibrato imitation of the music rotation Custom View, look at the effect

640?wx_fmt=gif
Renderings

To achieve this effect is mainly a patchwork approach adopted, which is to achieve the notes animated picture again achieve rotation animation effect and then merge the two together.

640?wx_fmt=jpeg

Look under the concept map

640?wx_fmt=jpeg
Concept map

Notes animation

Animation note here is the use of Bezier curve + PathMeasure + ValueAnimator achieved

640?wx_fmt=jpeg
Notes animation concepts

1. Draw Bezier curve: trajectory because the note is bottom-up, so we need to add Path path when first starting point to the bottom right, and then draw a Bezier curve.

path = new Path();//将起点移到右下角path.moveTo(getWidth(),getHeight()-getWidth()/6);//绘制自下而上的贝塞尔曲线path.quadTo(0,getHeight(),getWidth()/4,0);
//将起点移到右下角
path.moveTo(getWidth(),getHeight()-getWidth()/6);
//绘制自下而上的贝塞尔曲线
path.quadTo(0,getHeight(),getWidth()/4,0);

640?wx_fmt=gif

2.PathMeasure + ValueAnimator achieve the notes along the trajectory

private void initPath() {    //新建两个float数组pos用来存储每个轨迹点的坐标,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);    //设置重复执行动画    valueAnimator.setRepeatCount(ValueAnimator.INFINITE);    //设置为匀速运动    valueAnimator.setInterpolator(new LinearInterpolator());    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {        @Override        public void onAnimationUpdate(ValueAnimator animation) {float temp=(float) animation.getAnimatedValue();val= temp/2;//这里实现音符的透明度从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);    //获取每个点对应的坐标    pathMeasure.getPosTan(length*val,pos,tan);    //创建音符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);}
    //新建两个float数组pos用来存储每个轨迹点的坐标,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);
    //设置重复执行动画
    valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
    //设置为匀速运动
    valueAnimator.setInterpolator(new LinearInterpolator());
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
float temp=(float) animation.getAnimatedValue();
val= temp/2;
//这里实现音符的透明度从0~1~0的效果
if(temp>1){
    Music3.this.setAlpha(Math.abs(temp-2f));
}else {
    Music3.this.setAlpha(temp);
}
//更新界面
invalidate();
        }
    });
    valueAnimator.start();
}
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    //获取每个点对应的坐标
    pathMeasure.getPosTan(length*val,pos,tan);
    //创建音符BitMap宽高是逐渐放大的
    scaledBitmap = Bitmap.createScaledBitmap(bitmap, (int)(getWidth()/5*val)+4, (int)(getWidth()/5*val)+4true);
    canvas.drawPath(path,paint);
    canvas.drawBitmap(scaledBitmap,pos[0],pos[1],paint);
}

640?wx_fmt=gif
Notes animation

Picture rotation

Here I quote a third round Gallery

implementation 'de.hdodenhof:circleimageview:2.2.0''de.hdodenhof:circleimageview:2.2.0'

Achieve image rotation

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);new RotateAnimation(0360, 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);

640?wx_fmt=gif
Picture rotation

Finally, attach Source: https: //gitee.com/itfittnesss/DouYinMusic, more android learning and video Welcome to our knowledge of the planet, there are 1000+ junior partner, so you learn not lonely ~ *

After reading this article harvest? Please forward to sharing more people


Our knowledge of the opening of the third planet, has reached 1100 people, and be able to do three in a row has been very easy, there are a lot of old customers renewed, the current renewal rate of 50%, indicating that the people of our knowledge the planet is still very accepted, welcome to join us as soon as possible knowledge of the planet , the planet more information, see:

Welcome to Java and Android architecture community

How advanced Java for Android and become an architect?

He says two things

640?wx_fmt=jpeg

Click on the micro-channel scanning or receive Fanger Wei code of Android \ Python's \ AI \ of Java and other senior Advanced Resources

Click below to learn more information , "read the original  " Get

640?wx_fmt=gif

Thank you, boss, good-looking point ↓

Guess you like

Origin blog.csdn.net/xJ032w2j4cCjhOW8s8/article/details/90653825