7

我正在尝试制作一个动画,该动画将从当前位置滑动到屏幕中心,然后翻转。我让每个移动组件都正常工作,但是一旦我将它们全部放入带有 startoffset 的集合中,动画直到该偏移结束时才会开始,并且它会立即执行所有动画。非常感谢您对此的任何帮助。

slide_down.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- Slide down -->
    <translate 
        android:fromYDelta="0%" 
        android:toYDelta="100%"
        android:duration="1000"/>

    <!-- Set alpha to fully opaque -->
    <alpha 
        android:fromAlpha="0.8"
        android:toAlpha="1.0"
        android:duration="1000" />

    <!-- Flip image once it's in the center -->
    <!-- ***** HERE IS THE only offset I set ****** -->
    <scale
        android:fromXScale="0.0"
        android:toXScale="1.0"
        android:pivotX="50%"
        android:fromYScale="1.0"
        android:toYScale="1.0"
        android:startOffset="1000"
        android:duration="200" />
</set>

调用代码

Animation anim = AnimationUtils.loadAnimation(getActivity(), slideDirection);
        anim.setAnimationListener(new AnimationListener() {
            public void onAnimationStart(Animation animation) {             
            }

            public void onAnimationRepeat(Animation animation) {                
            }

            public void onAnimationEnd(Animation animation) {
                mCallBack.categorySelected(view.getId());
            }
        });

        view.clearAnimation();
        view.startAnimation(anim);

谢谢,德曼

4

1 回答 1

2

动画偏移总是从动画开始计算。如果你想让你的动画一个一个地播放,那么你必须自己计算偏移量。

以下将播放翻译 1 秒,然后 alpha 再播放一秒,然后缩放 200 毫秒 -

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- Slide down -->
    <translate 
        android:fromYDelta="0%" 
        android:toYDelta="100%"
        android:duration="1000"/>

    <!-- Set alpha to fully opaque -->
    <alpha 
        android:fromAlpha="0.8"
        android:toAlpha="1.0"
        android:startOffset="1000"
        android:duration="1000" />

    <!-- Flip image once it's in the center -->
    <!-- ***** HERE IS THE only offset I set ****** -->
    <scale
        android:fromXScale="0.0"
        android:toXScale="1.0"
        android:pivotX="50%"
        android:fromYScale="1.0"
        android:toYScale="1.0"
        android:startOffset="2000"
        android:duration="200" />
</set>
于 2012-12-12T18:41:06.627 回答