我正在使用框架动画来显示一些图像。但它只能在按钮操作中使用。我想在程序启动时调用这个函数。如何通过一个按钮来实现这一点?Android中的框架动画?
我用下面的代码为动画:
public class FrameAnimationActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.setupButton();
}
private void setupButton(){
Button b = (Button)this.findViewById(R.id.startFAButtonId);
b.setOnClickListener(
new Button.OnClickListener(){
public void onClick(View v){
parentButtonClicked(v);
}
});
}
private void parentButtonClicked(View v){
animate();
}
private void animate(){
ImageView imgView = (ImageView)findViewById(R.id.imageView);
imgView.setVisibility(ImageView.VISIBLE);
imgView.setBackgroundResource(R.drawable.frame_animation);
AnimationDrawable frameAnimation = (AnimationDrawable) imgView.getBackground();
if (frameAnimation.isRunning()){
frameAnimation.stop();
}
else{
frameAnimation.stop();
frameAnimation.start();
}
}
}
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/colored-ball1" android:duration="50" />
<item android:drawable="@drawable/colored-ball2" android:duration="50" />
<item android:drawable="@drawable/colored-ball3" android:duration="50" />
<item android:drawable="@drawable/colored-ball4" android:duration="50" />
<item android:drawable="@drawable/colored-ball5" android:duration="50" />
<item android:drawable="@drawable/colored-ball6" android:duration="50" />
<item android:drawable="@drawable/colored-ball7" android:duration="50" />
<item android:drawable="@drawable/colored-ball8" android:duration="50" />
</animation-list>
也许你应该查看一下API演示,它来自你的SDK的例子。当我是一个noob时,对我来说是一个很大的帮助,甚至现在.. – Shouvik 2010-10-12 04:47:59
@ Shouvik:我从API演示中获得了这些代码,但是它没有在按钮操作 – Jeff 2010-10-12 04:58:59