Android AnimationDrawable 在返回主屏幕时停止
我正在 Android 中开发一款游戏,其中启动器屏幕上有 2 个 AnimationDrawables。
这些动画一起运行得很好,但是当我离开屏幕然后返回到屏幕时,其中一个动画停止,另一个动画继续。
我的代码如下:
static AnimationDrawable animation;
static AnimationDrawable animation2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
animation = new AnimationDrawable();
animation.addFrame(getResources().getDrawable(R.drawable.j0), 200);
animation.addFrame(getResources().getDrawable(R.drawable.j1), 200);
animation.addFrame(getResources().getDrawable(R.drawable.j2), 200);
animation.addFrame(getResources().getDrawable(R.drawable.j3), 200);
animation.setOneShot(false);
animation2 = new AnimationDrawable();
animation2.addFrame(getResources().getDrawable(R.drawable.logo), 250);
animation2.addFrame(getResources().getDrawable(R.drawable.logo1), 250);
animation2.setOneShot(false);
ImageView imageAnim = (ImageView) findViewById(R.id.imageView1);
imageAnim.setBackgroundDrawable(animation);
imageAnim.post(new MenuAnimate());
ImageView imageAnima = (ImageView) findViewById(R.id.imageView2);
imageAnima.setBackgroundDrawable(animation2);
imageAnima.post(new MenuAnimate2());
class MenuAnimate implements Runnable {
public void run() {
Menu.animation.start();
}
}
class MenuAnimate2 implements Runnable {
public void run() {
Menu.animation2.start();
}
}
Xml 'menu':
<LinearLayout android:orientation="horizontal" android:layout_height="fill_parent" android:layout_width="wrap_content" android:weightSum="1" android:layout_weight="0.93">
<ImageView android:id="@+id/imageView1" android:layout_height="match_parent" android:layout_width="wrap_content"></ImageView>
<ImageView android:id="@+id/imageView2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="bottom"></ImageView>
</LinearLayout>
如果有人有任何想法,那就太棒了。
I am developing a game in Android in which the launcher screen has 2 AnimationDrawables on it.
The animations run fine together, however when I navigate away from the screen and then hit back to return to it, one of the animations stops, and the other continues.
My code is below:
static AnimationDrawable animation;
static AnimationDrawable animation2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
animation = new AnimationDrawable();
animation.addFrame(getResources().getDrawable(R.drawable.j0), 200);
animation.addFrame(getResources().getDrawable(R.drawable.j1), 200);
animation.addFrame(getResources().getDrawable(R.drawable.j2), 200);
animation.addFrame(getResources().getDrawable(R.drawable.j3), 200);
animation.setOneShot(false);
animation2 = new AnimationDrawable();
animation2.addFrame(getResources().getDrawable(R.drawable.logo), 250);
animation2.addFrame(getResources().getDrawable(R.drawable.logo1), 250);
animation2.setOneShot(false);
ImageView imageAnim = (ImageView) findViewById(R.id.imageView1);
imageAnim.setBackgroundDrawable(animation);
imageAnim.post(new MenuAnimate());
ImageView imageAnima = (ImageView) findViewById(R.id.imageView2);
imageAnima.setBackgroundDrawable(animation2);
imageAnima.post(new MenuAnimate2());
class MenuAnimate implements Runnable {
public void run() {
Menu.animation.start();
}
}
class MenuAnimate2 implements Runnable {
public void run() {
Menu.animation2.start();
}
}
Xml 'menu':
<LinearLayout android:orientation="horizontal" android:layout_height="fill_parent" android:layout_width="wrap_content" android:weightSum="1" android:layout_weight="0.93">
<ImageView android:id="@+id/imageView1" android:layout_height="match_parent" android:layout_width="wrap_content"></ImageView>
<ImageView android:id="@+id/imageView2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="bottom"></ImageView>
</LinearLayout>
If anyone has any idea it would be amazing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论