2010-11-11 140 views
26

我需要我的应用程序中的图像动画。 图像应该从左上角开始到屏幕中间。初始阶段图像尺寸会变小。在到达屏幕中间时,它的大小应该增加(即缩放应该发生)。图像不应该回到原来的位置。在动画之后,它应该放置在屏幕本身的中间。缩放和翻译动画

任何人都可以请帮忙。

回答

57

请在这里找到答案。 在/ res/anim文件夹内创建一个xml,并将下面的代码放入其中。

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:interpolator="@android:anim/linear_interpolator"> 
    <scale android:fromXScale="0.0" android:fromYScale="0.0" 
      android:toXScale="1.0" android:toYScale="1.0" 
      android:duration="700" android:fillBefore="false" /> 
    <translate android:fromXDelta="-200" android:fromYDelta="-200" 
      android:duration="700" /> 
</set> 

将下面的代码Java文件中:

Animation logoMoveAnimation = AnimationUtils.loadAnimation(this, R.anim.logoanimation); 
logoIV.startAnimation(logoMoveAnimation); 

logoanimation是我的动画XML文件的名称。

非常感谢所有为我提出问题的人。

+1

hi马修,我尝试了类似的动画,但图像会在动画结束后回到原始位置和缩放比例。如何防止图像在动画结束后回到原始位置和缩放比例? – Pravy 2011-07-14 10:24:37

+0

@Pravy: - 尝试添加到XML >>> android:repeatCount =“0” – Nipuna 2011-08-04 12:18:30

+4

@Pravy你也可以尝试添加以下xml行:android:fillAfter =“true” – 2011-12-06 22:17:14