开发者

TranslateAnimation applied to an ImageView leaves trail

开发者 https://www.devze.com 2023-03-17 10:41 出处:网络
I\'ve been recently struggling with the TranslateAnimation framework provided by the Android UI library.

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(sl开发者_如何学Goide);

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.


I think it is a layout design problem. Try giving

android:layout_width="fill_parent" 

instead of

android:layout_width="wrap_content"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号