gpt4 book ai didi

android - imageview android的波浪动画

转载 作者:行者123 更新时间:2023-11-29 15:07:05 32 4
gpt4 key购买 nike

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

我试过这个:

<?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" />

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

我想要这样的东西:

wave animation example image

最佳答案

要创建此效果,您需要使用 AnimationSet,并向其添加两个动画,一个动画是调整大小动画,主要是改变 View 的大小,另一个动画是淡入淡出动画基本上改变了这个 View 的 alpha 级别。

显然它们将应用于另一个 View 而不是图标 View 。

代码示例:

Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setDuration(1000);

AnimationSet animation = new AnimationSet(true);
animation.addAnimation(sizingAnimation);
animation.addAnimation(fadeOut);
this.setAnimation(animation);

编辑(15/09/2020):

调整动画大小:

 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>

显然,对于您的情况,所需的动画可能有所不同。

关于android - imageview android的波浪动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36127154/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com