I've been recently struggling with the TranslateAnimation framework provided by the Android UI library.
I have designed a RelativeLayout which has a GridView taking up the 80% of the screen more or less and an ImageView at the bottom of the screen. The latter it's supposed to be moving around the botttom of the screen constantly, 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 TranslateAnimation:
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 just calls this method on the onAnimationEnd function.
The matter is that when the image is moving from right to left it eventlually leaves bitmap traces on the screen, being removed after a while.
Any idea where the problem could be placed?
Thank you.
After you call iv.startAnimation(slide)
, you may need to call invalidate()
on the view's parent. I've had that problem before. I'm assuming you've solved the issue before, but hopefully this will be helpful for others.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With