撸一个直播点赞动画

live.gif

``````  一阶贝塞尔曲线，实际上就是一条连接两点的直线段。
二阶贝塞尔曲线，就是两点间的一条抛物线，利用一个控制点来控制抛物线的形状。
三阶贝塞尔曲线，则需要一个起点，一个终点，两个控制点来控制曲线的形状。
``````

``````    public class BesselEvaluator implements TypeEvaluator<float[]> {
private float point1[] = new float[2], point2[] = new float[2];

public BesselEvaluator(float[] point1, float[] point2) {
this.point1 = point1;
this.point2 = point2;
}

@Override
public float[] evaluate(float fraction, float[] point0, float[] point3) {
float[] currentPosition = new float[2];
currentPosition[0] = point0[0] * (1 - fraction) * (1 - fraction) * (1 - fraction)
+ point1[0] * 3 * fraction * (1 - fraction) * (1 - fraction)
+ point2[0] * 3 * (1 - fraction) * fraction * fraction
+ point3[0] * fraction * fraction * fraction;
currentPosition[1] = point0[1] * (1 - fraction) * (1 - fraction) * (1 - fraction)
+ point1[1] * 3 * fraction * (1 - fraction) * (1 - fraction)
+ point2[1] * 3 * (1 - fraction) * fraction * fraction
+ point3[1] * fraction * fraction * fraction;
return currentPosition;
}
}
``````

``````public class MainActivity extends AppCompatActivity {

long mLastTime = 0;
long mCurTime = 0;
private final int DELAY = 500;//连续点击的临界点
BubbleView bubbleView;
private int mClickCount = 0;
private int currLikeCount;
private TextView likeCount;
private Timer delayTimer;

private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
praiseRequest(mClickCount);
delayTimer.cancel();
super.handleMessage(msg);
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
bubbleView=(BubbleView)findViewById(R.id.praise_anim);
bubbleView.setDefaultDrawableList();
likeCount = (TextView) findViewById(R.id.like_count);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

mCurTime = System.currentTimeMillis();
if (mCurTime - mLastTime < DELAY) {
mClickCount++;
} else {
mClickCount = 1;
}
currLikeCount++;
likeCount.setText(String.valueOf(currLikeCount));
delay();
mLastTime = mCurTime;
bubbleView.startAnimation(bubbleView.getWidth(), bubbleView.getHeight());
}
});
}

private void delay() {

@Override
public void run() {
Message message = new Message();
mHandler.sendMessage(message);
}
};
delayTimer = new Timer();
}

/**
* 点赞请求网络
*/
private void praiseRequest(int count) {

}
}
``````

576DB36E-F179-47A0-A216-8C05381BCC94-1540-0000D86DB0CDA3D2.gif
test.gif

Android