Android Animation中fillAfter和fill

2015-12-07  本文已影响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>
上一篇 下一篇

猜你喜欢

热点阅读