9

I am having a problem with visual artifacts on the screen when applying the 3D transformation found here. I have changed this so it rotates around the x axis instead of the y. When i do a full 180 rotation (top going away from you at first) im getting single pixel line artifacts at the bottom area (bottom 10-20%) of every other view that this is applied to. I am using a selector as the background of a LinearLayout and then applying this Animation to it. Can anyone think of a quick solution to this issue?

Thanks for any help!

Dori
  • 18,283
  • 17
  • 74
  • 116
  • Just had the same issue, only comment I would add is that on 1.6 - pre 3.0 devices I get the artefacts, but on 3.0+ devices, enabling hardware acceleration solves the problem. – Matt Gaunt May 20 '12 at 14:29

2 Answers2

11

Turns out you just have to invalidate the parent view on each animation step. If you have a custom Animation object you can just do this inside Animation.applyTransformation(...)

Dori
  • 18,283
  • 17
  • 74
  • 116
  • 1
    glad to be of service - i knew answering my own questions would come in useful someday :) – Dori Apr 12 '12 at 10:27
  • 1
    Just ran into this as well, cleared up the problems I was having. This bug only seemed to affect 2.3 and lower devices (including the Kindle Fire) and seemed fine on my various 4.0+ devices. – jjb Jul 30 '12 at 04:55
0

I had a similiar problem with a 2D animation where a View is moved off screen (outside parent view). My solution was quite simple. In my custom View I simply invalidate the parent view to have it redrawn at every frame.

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    ((View) this.getParent()).invalidate();
    canvas.drawBitmap(icon, bm_x, bm_y, mPaint);
}
slott
  • 3,266
  • 1
  • 35
  • 30