gpt4 book ai didi

android - 动画中的延迟 (TranslateAnimation)

转载 作者:可可西里 更新时间:2023-11-01 18:45:39 26 4
gpt4 key购买 nike

有没有办法让动画暂停半秒?

我正在尝试使用 TranslateAnimation API 制作无限动画。因此,我将 RepeatCount 用作 Infinite。我还注意到有一个 setStartOffset(...) 方法可以解决我想要延迟启动动画的情况。但是,我找不到在每次“重启”之前进行延迟的方法。由于动画会发生无限次,每次动画重新开始时我都需要延迟。

有什么想法吗?

谢谢!!

最佳答案

这是一个例子:

首先是带有我们想要动画的图像的布局 (main.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />

</LinearLayout>

下一个是动画。放置在 res/anim 中,名为 anim_img.xml。该文件包含带有 android:startOffset="500"(以毫秒为单位)的翻译动画。这将设置每次动画开始时使用的偏移量:

<?xml version="1.0" encoding="utf-8"?>
<set>

<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="100%"
android:zAdjustment="top"
android:repeatCount="infinite"
android:startOffset="500"/>

</set>

最后但同样重要的是 - Activity 。哪个开始动画:

public class StackOverflowActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

ImageView iv_icon = (ImageView) findViewById(R.id.imageView1);

Animation a = AnimationUtils.loadAnimation(this, R.anim.anim_img);
a.setFillAfter(true);
a.reset();

iv_icon.startAnimation(a);
}
}

关于android - 动画中的延迟 (TranslateAnimation),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11268033/

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