gpt4 book ai didi

android - 在 Android 中的可绘制对象上应用动画

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:07:29 25 4
gpt4 key购买 nike

我正在为 Logo 添加发光动画效果。到目前为止,我已经设法使用 LayeredDrawable 获得 Logo 后面的发光图像,但我无法弄清楚如何为其设置动画。我发现 AlphaAnimation 可以达到预期的效果,但不幸的是我只能将它应用于 Views,而不是 Drawables。我怎样才能达到这个效果?

最佳答案

简单的例子

final ImageView imageView = (ImageView) findViewById(R.id.animatedImage);
final Button animated = (Button) findViewById(R.id.animated);
animated.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Drawable drawable = imageView.getDrawable();
if (drawable.getAlpha() == 0) {
ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 255));
animator.setTarget(drawable);
animator.setDuration(2000);
animator.start();
} else {
ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 0));
animator.setTarget(drawable);
animator.setDuration(2000);
animator.start();
}
}
});

方法getAlpha()在api 19中加入。不过限制不大,可以将状态保存在局部变量中。 ObjectAnimator 添加到 Android 3.0 (api 11),也许旧版本的 Android 你可以使用 nineoldandroids .我没有使用 nineoldandroids 进行测试。

关于android - 在 Android 中的可绘制对象上应用动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2902222/

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