gpt4 book ai didi

Android - 动画开始偏移量无法正常工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:17:37 25 4
gpt4 key购买 nike

我正在尝试制作一个动画,该动画将从当前位置滑动到屏幕中心,然后翻转。我让每个移动组件都正常工作,但是一旦我将它们全部放入带有 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);

谢谢,德曼

最佳答案

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

以下将播放 translate 1 秒,然后再播放 alpha 1 秒,然后缩放 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>

关于Android - 动画开始偏移量无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13846092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com