圆形揭露动画
今天看官方的动画效果无意发现了这个动画,可能是之前没怎么关注吧使用也很简单,其实就是一个圆形缩小或者变大的动画.官方连接如下:
https://developer.android.com/training/animation/reveal-or-hide-view
中文地址如下:
https://developer.android.google.cn/training/animation/reveal-or-hide-view
具体使用如下
主要使用的是ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, 0F)这个方法,其中后面两个参数用来控制变大还是缩小
fun animator(view: View) {
// Check if the runtime version is at least Lollipop
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// get the center for the clipping circle
val cx = view.width / 2
val cy = view.height / 2
// get the initial radius for the clipping circle
val initialRadius = Math.hypot(cx.toDouble(), cy.toDouble()).toFloat()
// create the animation (the final radius is zero)
val anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, 0F)
// make the view invisible when the animation is done
anim.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
super.onAnimationEnd(animation)
view.visibility = View.INVISIBLE
}
})
// start the animation
anim.start()
} else {
// set the view to visible without a circular reveal animation below Lollipop
view.visibility = View.INVISIBLE
}
}