TranslateAnimation applied to ImageView leaves a mark

I recently struggled with the TranslateAnimation platform provided by the Android UI library.

I developed a RelativeLayout that has a GridView occupying 80% of the screen more or less, and an ImageView at the bottom of the screen. The latter is supposed to constantly move around the bottle of the screen with random directions.

Here's the layout:

<ImageView android:id="@+id/bottom_fish" android:layout_alignParentBottom="true" android:adjustViewBounds="true" android:cropToPadding="true" android:scaleType="centerInside" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="40dp" android:layout_alignParentLeft="true" android:layout_weight="0" android:src="@drawable/little_fish_right" ></ImageView> <GridView android:id="@+id/gridview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_above="@id/mouin_bottom" android:columnWidth="90dp" android:numColumns="4" android:verticalSpacing="10dp" android:horizontalSpacing="10dp" android:stretchMode="columnWidth" android:gravity="center" /> 

And here's the TranslationAnimation:

 TranslateAnimation slide = new TranslateAnimation(x0, newX, y0, newY); slide.setFillAfter(true); slide.setInterpolator(new LinearInterpolator()); slide.setDuration(duration); slide.setAnimationListener(animationListener); iv.startAnimation(slide); x0 += newX; y0 += newY; 

The AnimationListener assigned to the animation simply calls this method in the onAnimationEnd function.

The fact is that when the image moves from right to left, it ultimately leaves raster traces on the screen, moving away after a while.

Any idea where the problem could be posed?

Thanks.

+7
source share
2 answers

After calling iv.startAnimation(slide) you may need to call invalidate() in the parent view. I used to have this problem. I assume that you solved the problem earlier, but I hope it will be useful for others.

+1
source

I think this is a layout design issue. Try to give

 android:layout_width="fill_parent" 

instead

 android:layout_width="wrap_content" 
0
source

All Articles