【问题标题】:Wave animation for imageview androidimageview android的波浪动画
【发布时间】:2016-03-21 09:25:35
【问题描述】:

我正在尝试创建一个带有波浪动画的按钮。 我不想改变图像的大小,而是从图片和外部做波浪的效果。

我试过这个:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

<objectAnimator
    android:propertyName="scaleX"
    android:duration="2000"
    android:valueFrom="1.0"
    android:valueTo="1.3"
    android:repeatMode="reverse"
    android:repeatCount="infinite"
    android:valueType="floatType" />

<objectAnimator
    android:propertyName="scaleY"
    android:duration="2000"
    android:valueFrom="1.0"
    android:valueTo="1.3"
    android:repeatMode="reverse"
    android:repeatCount="infinite"
    android:valueType="floatType" />

但这会改变图像的大小,而不是从中发送波形。

我想要这样的东西:

【问题讨论】:

  • 获取另一个视图并将动画应用到该视图

标签: android android-animation android-imageview


【解决方案1】:

要创建这个效果,你需要使用AnimationSet,然后添加两个动画,一个动画是调整大小动画,基本上是改变视图的大小,另一个动画是一个渐变动画,基本上是改变 alpha此视图的级别。

显然它们会被应用到另一个视图而不是图标视图。

代码示例:

Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setDuration(1000);
 
AnimationSet animation = new AnimationSet(true);
animation.addAnimation(sizingAnimation);
animation.addAnimation(fadeOut);
this.setAnimation(animation);

已编辑(2020 年 9 月 15 日):

调整动画大小:

 private Animation getResizeAnimation(Context aContext, boolean enlarge) {
    Animation resizeAnimation;
    if (enlarge) {
        resizeAnimation = AnimationUtils.loadAnimation(aContext, R.anim.scale_up_card);
    } else {
        resizeAnimation = AnimationUtils.loadAnimation(aContext, R.anim.scale_down_card);
    }
    resizeAnimation.setFillAfter(true);
    return resizeAnimation;
}

scale_up_card 在哪里:

<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="1.0"
       android:fromYScale="1.0"
       android:toXScale="1.03"
       android:toYScale="1.03"
       android:pivotX="50%"
       android:pivotY="10%"
       android:duration="100">
</scale>
</set>

还有scale_down_card:

<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="1.03"
       android:fromYScale="1.03"
       android:toXScale="1.0"
       android:toYScale="1.0"
       android:pivotX="50%"
       android:pivotY="10%"
       android:duration="100">
</scale>
</set>

显然,对于您而言,所需的动画可能不同。

【讨论】:

  • 什么是 sizingAnimation ?
  • sizingAnimation 到底是什么??
  • @KingofMasses 大小动画添加到答案。
  • @VishistVarugeese 大小动画添加到答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-10
  • 2019-11-14
  • 2020-08-11
  • 1970-01-01
  • 1970-01-01
  • 2017-05-16
  • 1970-01-01
相关资源
最近更新 更多