Android - 动画开始偏移量不起作用

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);

感谢您,Dman。
1个回答

2

动画偏移量始终从动画开始计算。如果您希望您的动画一个接一个地播放,则必须自行计算偏移量。

以下内容将先播放1秒钟的翻译,然后再播放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>

谢谢回复。我想要的是同时进行翻译和alpha处理,当图像移动到中心并完全不透明时,开始翻转动画。 - DMCApps

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接