0

每次单击按钮时,我都想制作一个淡入淡出动画。我开始只检查淡出,在第一次点击时,淡出似乎工作得很好。但是当我再次单击时,动画会从上到下淡出,使它看起来很糟糕并且被剪掉了。

动画:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1.0"
       android:toAlpha="0.0"
       android:interpolator="@android:anim/accelerate_interpolator"
   android:duration="1000" />
</set>

编码:

Animation fadeOut = AnimationUtils.loadAnimation(myActivity.this, R.anim.fade_out);
LinearLayout myBackground=(LinearLayout)findViewById(R.id.myBackground);
myBackground.setAnimation(fadeOut);

我错过了什么?谢谢!

4

1 回答 1

0

在以下文件夹中制作动画 ris->anim->fade_anim.xml 添加下面的 xml

 <alpha
    android:duration="2000"
    android:fromAlpha="1"
    android:toAlpha="0.0"
    android:repeatCount="infinite"/>

去java课

//make animation object
final Animation myAnim = AnimationUtils.loadAnimation(getContext(),    R.anim.bounce_anim);
    myAnim.setRepeatMode(Animation.INFINITE);

//get View on which on you want to apply animation I am applying on imageView
mLayout.findViewById(R.id.imageView).startAnimation(myAnim);
于 2016-09-01T15:55:24.107 回答