效果
代码
button1=findViewById(R.id.button);
button1.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onClick(View v) {
int cx=button1.getWidth()/2;
int cy=button1.getHeight()/2;
float radius=button1.getWidth();
Animator anim= ViewAnimationUtils.createCircularReveal(button1,cx,cy,radius,0);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
button1.setVisibility(View.INVISIBLE);
}
});
anim.start();
}
});
说明
createCircularReveal方法创建了一个Animator,设置动画的中心位置(cx,cy),起始半径(radius)、结束半径(0)。
在动画播放之前,我设置了一个事件监听器,一旦动画播放完毕,则将按钮设置为不可见(invisible)的状态。