<p>
- 方法參數(shù)
/**
* @param view 執(zhí)行動畫的view
* @param centerX 動畫圓中心的X坐標
* @param centerY 動畫圓中心的Y坐標
* @param startRadius 動畫圓的起始半徑
* @param endRadius 動畫圓的結束半徑
*/
public static Animator createCircularReveal(View view, int centerX, int centerY, float startRadius, float endRadius) {
throw new RuntimeException("Stub!");
}
- 使用方法
@Override
public void onClick(View view) {
// 動畫圓中心的X坐標
int centerX = view.getWidth() / 2;
// 動畫圓中心的Y坐標
int centerY = view.getHeight() / 2;
// 動畫圓的起始半徑:從圓心開始執(zhí)行動畫
float startRadius = 0;
// 動畫圓的結束半徑:計算長寬的斜邊長
float endRadius = (float) Math.hypot((double) (view.getWidth() / 2), (double) (view.getHeight() / 2));
// 定義揭露動畫
Animator animator = ViewAnimationUtils.createCircularReveal(
view, centerX, centerY, startRadius, endRadius
);
// 設置動畫監(jiān)聽:可根據(jù)需求在動畫開始或結束時做相應操作
animator.addListener(new MyAnimatorListener());
// 設置動畫持續(xù)時間
animator.setDuration(1000);
// 開始執(zhí)行動畫
animator.start();
}
// 動畫監(jiān)聽
private class MyAnimatorListener implements Animator.AnimatorListener {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
}