Android-动画视图中的getAlpha() [英] Android - getAlpha() from Animated View

查看:466
本文介绍了Android-动画视图中的getAlpha()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的动画:

Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new DecelerateInterpolator());
fadeOut.setDuration(350);
myView.startAnimation(fadeOut);

我正在尝试让其Alpha在动画中如此播放:

I am trying is to get its Alpha durring the Animation as such:

System.out.println(myView.getAlpha());

但是,在整个动画中始终返回 1.0。如何在动画过程中获取 myView 的实际Alpha值?

However, it always returns "1.0" throughout the animation. How can I obtain the actual alpha value of myView during the animation process?

推荐答案

通过将 Transformation AlphaAnimation 结合使用,您可能可以直接从 AlphaAnimation 对象而不是您的 View

By using Transformation with your AlphaAnimation, you may be able to retrieve alpha value directly from your AlphaAnimation object instead of your View.

使用Transformation的目的:

Purpose of using Transformation:


定义要在动画的某个时间点应用的变换。

Defines the transformation to be applied at one point in time of an Animation.






步骤:


  1. 创建一个新的 Transformation.java 类,如 https://sourcegraph.com/android.googlesource.com/platform/frameworks/base/-//blob /core/java/android/view/animation/Transformation.java

初始化 Transformation 对象:

private Transformation myTransformation;
mTransformation = new Transformation();


  • 使用您的代码:

  • Using your code:

    Animation fadeOut = new AlphaAnimation(1, 0);
    fadeOut.setInterpolator(new DecelerateInterpolator());
    fadeOut.setDuration(350);
    


  • 获取视图层次结构开始绘制的时间(以毫秒为单位):

  • Get the time at which the drawing of the view hierarchy started (in milliseconds):

    final long time = myView.getDrawingTime();
    


  • 获取转换以在指定的时间点应用。最后,获得动画过程中的实际Alpha值:

  • Get the transformation to apply at a specified point in time. Finally, obtain the actual alpha value during the animation:

    fadeOut.getTransformation(time, myTransformation);
    final float myAlphaValue = myTransformation.getAlpha();
    







  • 资源
    https://sourcegraph.com/android.googlesource.com/platform/frameworks/base/-/blob/core/java/android/widget/ProgressBar.java# L1699
    https://developer.android。 com / reference / android / view / animation / Animation.html
    https://developer.android.com/reference/android/view/animation/Transformation.html

    这篇关于Android-动画视图中的getAlpha()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆