圓形揭露動畫
今天看官方的動畫效果無意發(fā)現(xiàn)了這個動畫,可能是之前沒怎么關(guān)注吧使用也很簡單,其實就是一個圓形縮小或者變大的動畫.官方連接如下:
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)這個方法,其中后面兩個參數(shù)用來控制變大還是縮小
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
}
}