Tutorial :Why is my animation leaving a trail?


I'm animating a an ImageView from the left to the right of the screen using a translate animation. The ImageView is place inside a RelativeLayout over the top of my main layout using FrameLayout.

When I run the animation on the emulator everything works pretty well but when I use run it on my G1 it leaves visual artifacts behind and effects the rendering of the text component behind it.

Is this a performance issue and I'm being too ambitious or is it a bug I can overcome?

If it is a performance issue is there anything I can do to improve things?


I now this may be a little old, but I just found this:


Not sure what android version your using, but it may be a bug in the android libraries!

Looks like that's what the problem is for me! :)

... Dontcha just love it when its not your fault! :D


I was also experiencing the same issue on 2.3.

Invalidating the container of the moving view ( the layout in which the moving view resides ) in Animation.applyTransformation fixed it for me.


Android - Artifacts using Animation


Here's a workaround I found that solved this for me: "An easy workaround would be to pad your image with a small (1 pixel should do it) transparent region on the right/bottom - this would have no effect on how it would look, but it would force an invalidation of a region slightly larger than the actual image and thus compensate for the bug."



Without actually seeing the problem is sounds like you're not clearing the display buffer before writing the next frame. It doesn't sound like a performance issue to me.

Do you have control over whether the device does double buffering or not?

Given that it works on the emulator this could point to either a problem with the emulator or a bug in your code that isn't showing up on the emulator (which I suppose is technically a problem with the emulator!) rather than a performance issue.


I would suggest using a SurfaceView for animation. It is double-buffered, so it should eliminate flickering if you use it properly. If you want an example, the LunarLander demo included in the sdk shows this really well. Also, if you have a more specific question with code, ask away.

As for general Android performance, it is very possible to have reasonably high frame rates, so you aren't expecting too much.


This is happening to me as well. I'm using an emulator using 1.6 with the Google APIs, and I just confirmed that it happens on a Nexus One running FRF83. Here's the relevant code:

Animation a = new TranslateAnimation(0.0f, 0.0f, 100.0f, 0.0f);  a.setDuration(2000);  this.myView.startAnimation(a);  

Here's the relevant code for instantiating the view:

View v = new View(this.getApplication());  LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 80);  v.setLayoutParams(params);  v.setBackgroundColor(0xFFFF0000);  //  LinearLayout layout = (LinearLayout)this.findViewById(R.id.theLayout);  layout.addView(v);  //  v.setOnClickListener(new View.OnClickListener() {            public void onClick(View arg0) {          // TODO Auto-generated method stub          doAnimation();      }  });  //  myView = v;  

So basically, the double buffering etc, is being handled by the OS, and I have no control over it at all.


I had a similar problem on Android 2.3, so the bug may still in exist. I was using an ImageView with a PNG which had some transparent parts. This imageview was leaving trails when animated with TranslateAnimation. Using a fake background drawable for the imageview elimanated the trail (I used a drawable as background).


I figured this out on Jelly bean i was experiencing this in a gallery view while performing some animation. It looks more like a drawing issue not cpu ....

make your activity implement the interface AnimatorListener ..... override the below method and pick which one you want to redraw your view in

 @Override  public void onAnimationEnd(Animator animation) {      // TODO Auto-generated method stub        mView.requestLayout();      Toast.makeText(this, "animation ended", 0).show();  }    @Override  public void onAnimationRepeat(Animator animation) {      // TODO Auto-generated method stub      mView.requestLayout();  }    @Override  public void onAnimationStart(Animator animation) {      // TODO Auto-generated method stub      mView.requestLayout();  }  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »