9

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?

apaderno
  • 28,547
  • 16
  • 75
  • 90
Tom Martin
  • 2,498
  • 3
  • 29
  • 37
  • 4
    Can you provide any code for us to look at? Are you doing anything else with the frame layout? What version of the SDK are you using (i.e. cupcake?) – jamesh Jun 22 '09 at 22:12
  • Is this the class you're using? http://developer.android.com/reference/android/view/animation/TranslateAnimation.html – Jarett Millard Jun 29 '09 at 16:51
  • Good question, I've had this problem also, but it shows in the emulator too! Its occurring when I'm animating a 3D rotation of a view in a FrameLayout, perhaps its a function/bug of the FrameLayout? I'm going to see if I can use the surface view... – Andy Jun 29 '10 at 14:35

8 Answers8

10

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.

See:

Android - Artifacts using Animation

Community
  • 1
  • 1
Matthijs
  • 1,315
  • 12
  • 12
3

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

http://groups.google.com/group/android-developers/browse_thread/thread/5481450f8b71a26c/e750730b9953d9a8?lnk=gst&q=animation+leaves+trails#e750730b9953d9a8

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

Andy
  • 2,977
  • 2
  • 39
  • 71
  • Almost certainly. No longer have the code to retest though :( I gave up on that animation and went with one that wouldn't leave a trail. – Tom Martin Jul 13 '10 at 00:11
2

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."

http://code.google.com/p/android/issues/detail?id=22151

Brian Christensen
  • 5,076
  • 2
  • 16
  • 7
  • By far the simplest solution to this. Thanks! – Ross Hambrick Apr 19 '12 at 20:26
  • this one works . no idea why it occurs , since one of the main android developers wrote that it was fixed ages ago : http://groups.google.com/group/android-developers/browse_thread/thread/5481450f8b71a26c/e750730b9953d9a8?lnk=gst&q=animation+leaves+trails#e750730b9953d9a8 – android developer May 19 '12 at 22:31
  • Very interesting! I'm guessing that this works because of the conversion from actual to density independent pixels. The ring of invisible accounts for some sloppiness. – SMBiggs Dec 02 '15 at 17:44
0

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.

ChrisF
  • 134,786
  • 31
  • 255
  • 325
  • I'm using the animation framework provided by the Android framework so I have neither control over the double buffering or the display buffer. To me it looks like a bug. If this were a performance issue because my requirements were too ambitious the animation should just be jerky/have a low framerate. It performs reasonably well, it just leaves what look like pieces of the image behind it. They're cleaned up fairly quickly but it doesn't look good. – Tom Martin Jun 18 '09 at 21:11
  • @Tom - I think I've reached the limit of what I can suggest. I don't really know the environment you're developing in - but I do know animation having worked with real time 3D graphics for a number of years and I've encountered similar sounding problems. But as I said, without actually seeing what's going on it's difficult to diagnose the problem. – ChrisF Jun 19 '09 at 08:13
0

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.

AdamC
  • 16,087
  • 8
  • 51
  • 67
0

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();
}
j2emanue
  • 60,549
  • 65
  • 286
  • 456
0

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.

0

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).

Daniel Novak
  • 2,746
  • 3
  • 28
  • 37