缩放和翻译动画

Anj*_*nju 27 android android-animation

我需要在我的应用程序中为图像添加动画.图像应从左上角开始直到屏幕中间.初始阶段的图像尺寸会变小.当到达屏幕中间时,它的大小应该增加(即应该进行缩放).图像不应该回到原来的位置.它应该在动画之后放置在屏幕中间.

谁能请帮忙.

Anj*_*nju 61

请在这里找到答案.在/ 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>
Run Code Online (Sandbox Code Playgroud)

将以下代码放在java文件中:

Animation logoMoveAnimation = AnimationUtils.loadAnimation(this, R.anim.logoanimation); 
logoIV.startAnimation(logoMoveAnimation);
Run Code Online (Sandbox Code Playgroud)

logoanimation是我的动画xml文件的名称.

感谢所有试过我的问题的人.

  • @Pravy你也可以尝试添加以下xml行:android:fillAfter ="true" (4认同)
  • 为了避免图像恢复到原始大小,我不得不添加动画侦听器并手动调整其onAnimationEnd属性值.`animation.setAnimationListener(new AnimationListener {...})`这可能与此按钮中与该按钮相关的视图问题有关.[https://developer.android.com/guide/topics/graphics/prop-animation.html#how] (2认同)