美文网首页
Android Animation中fillAfter和fill

Android Animation中fillAfter和fill

作者: 华枯荣 | 来源:发表于2015-12-07 16:32 被阅读1112次

有的时候,在xml文件中使用动画的fillAfterfillBefore属性,会没有任何效果。后来在stackoverflow上发现了相关解答

对于fillAfterfillBefore属性的使用,只有以下两种方式有效果:

  • 在代码中使用

animation.setFillEnabled(true);
animation.setFillAfter(true);

- **在xml文件的根标签中使用**
    + 单个动画是根标签
    
            <?xml version="1.0" encoding="utf-8"?>
            <translate  
                xmlns:android="http://schemas.android.com/apk/res/android"  
                android:fillAfter="true"
                android:fillEnabled="true"
                android:fromXDelta="0%"
                android:toXDelta="-100%"
                android:duration="500" />
  
    + 动画集是根标签
        
            <?xml version="1.0" encoding="utf-8"?>
            <set
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:fillAfter="true"
                android:fillEnabled="true">
                <translate
                    android:fromXDelta="0%"
                    android:toXDelta="-100%"
                    android:duration="500" />
            </set>

相关文章

网友评论

      本文标题:Android Animation中fillAfter和fill

      本文链接:https://www.haomeiwen.com/subject/tvdehttx.html