gpt4 book ai didi

java - Android继续循环动画

转载 作者:行者123 更新时间:2023-11-29 19:29:12 24 4
gpt4 key购买 nike

我已经根据这里的答案在我的动画中尝试了几种循环,例如 animation.setRepeatCount(Animation.INFINITE);或 anim.xml 文件中的 android:repeatcount="infinite".. 甚至在 java 上尝试了 while(true) 循环,但似乎都不起作用。

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">

<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="3000" />

<translate
android:fromXDelta="0.0"
android:toXDelta="0.0"
android:fromYDelta="0.0"
android:toYDelta="100.0"
android:startOffset="3000"
android:duration="3000"
android:repeatCount="infinite"/>

</set>

我的 java 是:

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img = (ImageView) findViewById(R.id.img);
animation = AnimationUtils.loadAnimation(this, R.anim.halloweenanim);

img.startAnimation(animation);
animation.setRepeatCount(Animation.INFINITE);

//hallo.setBackgroundResource(R.drawable.halloweenimg);
//animation2 = (AnimationDrawable) hallo.getBackground();
//animation2 = (AnimationDrawable) img.getBackground();
//animation.start();
};

最佳答案

实际上 AnimationSet 有一个错误代码。甚至医生 here

repeatCount, fillEnabled: These properties are ignored for AnimationSet.

你可以做的是删除 animation.setRepeatCount(Animation.INFINITE);并为每个动画标签设置 android:repeatCount="infinite",而不是父集标签。

关于java - Android继续循环动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40520259/

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