解释
******动画结束时,停留在最后一帧*********
<set android:fillAfter="true" android:fillBefore="false">
******动画结束时,停留在第一帧********
<set android:fillAfter="false" android:fillBefore="true">
使用
第一种:通过XML形式创建AlphaAnimation
1.fade_out_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<!--set -> Animation-->
<!--alpha -> AlphaAnimation-->
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:fillAfter = "true"
android:duration = "1000"
/>
2.MainActivity.kt
private fun testAlphaCode(from:Float,to:Float){
val alphaAnimation = AlphaAnimation(from,to).apply {
//持续时间1s
duration = 1000
//动画结束时停留在最后一帧
fillAfter = true
//重复次数无限Animation.INFINITE,重复了3次
//repeatCount = 2
//重复模式为反转
//repeatMode = Animation.REVERSE
view.startAnimation(alphaAnimation)
}
第二种:通过代码形式创建AlphaAnimation
//使用时调用这个函数即可
private fun testAlphaCode(from:Float,to:Float){
AlphaAnimation(from,to).apply {
//持续时间1s
duration = 1000
//动画结束时停留在最后一帧
fillAfter = true
//重复次数无限Animation.INFINITE,重复了3次
//repeatCount = 2
//重复模式为反转
//repeatMode = Animation.REVERSE
}