Android Animation中fillAfter和fillBefore的使用

有的时候,在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>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容