【问题标题】:Fade animation - not constant behavior Android淡出动画 - 不是恒定的行为 Android
【发布时间】:2016-09-01 23:55:24
【问题描述】:

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

动画:

<?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);

我错过了什么?谢谢!

【问题讨论】:

  • 完成 setAnimation 后,您还需要启动动画...所以 myBackground.startAnimation
  • 不敢相信...我没有意识到我使用的是 Set 而不是 Start! BTY 我不需要 Set 它只需要 startAnimation 就可以正常工作。谢谢你:)
  • @Tomik 我对此不熟悉,我需要做什么?

标签: android animation fade


【解决方案1】:

在以下文件夹 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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-24
    • 1970-01-01
    • 2011-10-11
    • 2011-09-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多