gpt4 book ai didi

android - 在 onCreate 方法上运行 android 动画

转载 作者:行者123 更新时间:2023-11-30 04:27:00 24 4
gpt4 key购买 nike

我想在应用程序启动后立即运行我的 android 动画。
我在 thunder.xml 中使用带有动画列表的帧动画。我的代码如下。

ImageView img = (ImageView) findViewById(R.id.animlist);    
img.setBackgroundResource(R.drawable.thunder);
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
frameAnimation.start();

但是这个正在运行但是没有显示动画。如果我创建一个按钮并将其设置为该按钮的 onClick 事件,那么它可以正常工作。但我想在应用程序启动后立即运行我的 android 动画。请帮我 ..提前致谢

最佳答案

试试这个代码,它可能对你有帮助 -

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
animation = (ImageView)findViewById(R.id.imageAnimation);
animation.setBackgroundResource(R.drawable.animation);
}

public void onWindowFocusChanged (boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
AnimationDrawable frameAnimation =
(AnimationDrawable) animation.getBackground();
if(hasFocus) {
frameAnimation.start();
} else {
frameAnimation.stop();
}
}

关于android - 在 onCreate 方法上运行 android 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8322236/

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