我正在做一个帧到帧动画。我的问题是我已经在我的动画xml中提供了大约10个可绘制的图像。但只有前两个和后两个显示并非所有图像。我正在对这个图像进行翻译。翻译后只有帧动画开始。翻译正在发生,帧动画也在发生,但它没有显示所有帧。这是我的动画xml。只显示了frog_01和frog_02。
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true" >
<item
android:drawable="@drawable/frog_01"
android:duration="70"/>
<item
android:drawable="@drawable/frog_02"
android:duration="70"/>
<item
android:drawable="@drawable/frog_03"
android:duration="70"/>
<item
android:drawable="@drawable/frog_04"
android:duration="70"/>
<item
android:drawable="@drawable/frog_05"
android:duration="70"/>
<item
android:drawable="@drawable/frog_04"
android:duration="70"/>
<item
android:drawable="@drawable/frog_03"
android:duration="70"/>
<item
android:drawable="@drawable/frog_02"
android:duration="70"/>
<item
android:drawable="@drawable/frog_01"
android:duration="70"/>
</animation-list>
以下是我用于翻译和帧动画的代码......
public void frogAnim() {
frogView.clearAnimation();
final TranslateAnimation fslide2 = new TranslateAnimation(10, 65, 0, 0);
fslide2.setDuration(400);
fslide2.setFillAfter(true);
fslide2.setAnimationListener(fanimationListener1);
frogView.startAnimation(fslide2);
c = false;
}
AnimationListener fanimationListener1 = new AnimationListener() {
public void onAnimationEnd(Animation arg0) {
c = true;
frogView.setBackgroundResource(R.drawable.frog_movement);
frogFrameAnimation = (AnimationDrawable) frogView.getBackground();
frogFrameAnimation.start();
playAudioFileListener(R.raw.frog, player);
CountDownTimer count = new CountDownTimer(200, 700) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
frogFrameAnimation.stop();
titileAnimMusic(R.drawable.frog_title,
R.anim.alpha_fade_in1, R.raw.vo_child_frog, player);
}
};
count.start();
}
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationStart(Animation animation) {
}
};
答案 0 :(得分:1)
你试试这个代码......
http://www.coderzheaven.com/2011/04/23/android-frame-animation/
=====================
在班级
final ImageView img =(ImageView) findViewById(R.id.imageView1);
img.setBackgroundResource(R.layout.animation);
img.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
AnimationDrawable anim=(AnimationDrawable) img.getBackground();
anim.start();
}
});
布局文件夹中的animation.xml
<animation-list android:oneshot="false"
<item android:drawable="@drawable/animation_00031" android:duration="30"/>
<item android:drawable="@drawable/animation_00032" android:duration="30"/>
<item android:drawable="@drawable/animation_00033" android:duration="30"/>
<item android:drawable="@drawable/animation_00034" android:duration="30"/>
<item android:drawable="@drawable/animation_00035" android:duration="30"/>
<item android:drawable="@drawable/animation_00036" android:duration="30"/>
<item android:drawable="@drawable/animation_00037" android:duration="30"/>
<item android:drawable="@drawable/animation_00038" android:duration="30"/>
<item android:drawable="@drawable/animation_00039" android:duration="30"/>
<item android:drawable="@drawable/animation_00040" android:duration="30"/>
<item android:drawable="@drawable/animation_00041" android:duration="30"/>
<item android:drawable="@drawable/animation_00042" android:duration="30"/>
<item android:drawable="@drawable/animation_00043" android:duration="30"/>
<item android:drawable="@drawable/animation_00044" android:duration="30"/>
<item android:drawable="@drawable/animation_00045" android:duration="30"/>
<item android:drawable="@drawable/animation_00046" android:duration="30"/>
<item android:drawable="@drawable/animation_00047" android:duration="30"/>
<item android:drawable="@drawable/animation_00048" android:duration="30"/>
<item android:drawable="@drawable/animation_00049" android:duration="30"/>
<item android:drawable="@drawable/animation_00050" android:duration="30"/>
<item android:drawable="@drawable/animation_00051" android:duration="30"/>
<item android:drawable="@drawable/animation_00052" android:duration="30"/>
<item android:drawable="@drawable/animation_00053" android:duration="30"/>
<item android:drawable="@drawable/animation_00054" android:duration="30"/>
<item android:drawable="@drawable/animation_00055" android:duration="30"/>
<item android:drawable="@drawable/animation_00056" android:duration="30"/>
<item android:drawable="@drawable/animation_00057" android:duration="30"/>
<item android:drawable="@drawable/animation_00058" android:duration="30"/>
<item android:drawable="@drawable/animation_00059" android:duration="30"/>
<item android:drawable="@drawable/animation_00060" android:duration="30"/>
<item android:drawable="@drawable/animation_00061" android:duration="30"/>
<item android:drawable="@drawable/animation_00062" android:duration="30"/>
<item android:drawable="@drawable/animation_00063" android:duration="30"/>
在main.xml中
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
我试过这个,这对我来说非常有用......
答案 1 :(得分:1)
试试这个......
img=(ImageView) findViewById(R.id.imageView1);
img.setBackgroundResource(R.layout.animation);
Animation animation =AnimationUtils.loadAnimation(this,R.anim.translate);
img.startAnimation(animation);//calling translate animation
CallDelay(1000);
public void CallDelay(long time)
{
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
public void run()
{
myanimation();
}
}, time);
}
public void myanimation()
{
//calling frame animation
AnimationDrawable anim=(AnimationDrawable) img.getBackground();
anim.start();
}
在一个动画之后尝试延迟调用..