解釋
******動(dòng)畫結(jié)束時(shí),停留在最后一幀*********
<set android:fillAfter="true" android:fillBefore="false">
******動(dòng)畫結(jié)束時(shí)丐膝,停留在第一幀********
<set android:fillAfter="false" android:fillBefore="true">
使用
第一種:通過(guò)XML形式創(chuàng)建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 {
//持續(xù)時(shí)間1s
duration = 1000
//動(dòng)畫結(jié)束時(shí)停留在最后一幀
fillAfter = true
//重復(fù)次數(shù)無(wú)限Animation.INFINITE,重復(fù)了3次
//repeatCount = 2
//重復(fù)模式為反轉(zhuǎn)
//repeatMode = Animation.REVERSE
view.startAnimation(alphaAnimation)
}
第二種:通過(guò)代碼形式創(chuàng)建AlphaAnimation
//使用時(shí)調(diào)用這個(gè)函數(shù)即可
private fun testAlphaCode(from:Float,to:Float){
AlphaAnimation(from,to).apply {
//持續(xù)時(shí)間1s
duration = 1000
//動(dòng)畫結(jié)束時(shí)停留在最后一幀
fillAfter = true
//重復(fù)次數(shù)無(wú)限Animation.INFINITE,重復(fù)了3次
//repeatCount = 2
//重復(fù)模式為反轉(zhuǎn)
//repeatMode = Animation.REVERSE
}