Android 将圆形分隔缝动画居中
我正在尝试创建一个从Android 将圆形分隔缝动画居中,android,animation,Android,Animation,我正在尝试创建一个从视图(API 21+)的中心开始的圆形显示动画。我尝试对x使用View.getLeft()和View.getRight()的平均值,对y使用View.getTop()和View.getBottom()的平均值(这就是所做的,但是如果我的视图被CoordinatorLayout偏移,则值是错误的。我在一个OnPreDrawListener中获取值,因此已经对视图进行了测量。我发现使用View.getDrawingRect()可以做到这一点 private Animator cr
视图
(API 21+)的中心开始的圆形显示动画。我尝试对x使用View.getLeft()
和View.getRight()
的平均值,对y使用View.getTop()
和View.getBottom()的平均值(这就是所做的,但是如果我的视图被CoordinatorLayout
偏移,则值是错误的。我在一个OnPreDrawListener
中获取值,因此已经对视图进行了测量。我发现使用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);
}