以圆形显示动画为中心

key*_*rdr 2 animation android

我正在尝试创建一个从View(API 21+)中心开始的圆形显示动画.我试着用的平均值View.getLeft()View.getRight()x和View.getTop()View.getBottom()y的(这是什么呢,但如果我的观点是由偏移CoordinatorLayout,该值是错误的.我抓住一个中值OnPreDrawListener,所以查看已测.

key*_*rdr 6

我发现使用View.getDrawingRect()诀窍.

private Animator createCenteredReveal(View view) {
  // Could optimize by reusing a temporary Rect instead of allocating a new one
  Rect bounds = new Rect();
  view.getDrawingRect(bounds);
  int centerX = bounds.centerX();
  int centerY = bounds.centerY();
  int finalRadius = Math.max(bounds.width(), bounds.height());
  return ViewAnimationUtils.createCircularReveal(view, centerX, centerY, 0f, finalRadius);
}
Run Code Online (Sandbox Code Playgroud)