Skip to content Skip to sidebar Skip to footer

Android - Getalpha() From Animated View

I have an animation like this: Animation fadeOut = new AlphaAnimation(1, 0); fadeOut.setInterpolator(new DecelerateInterpolator()); fadeOut.setDuration(350); myView.startAnimation(

Solution 1:

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

Purpose of using Transformation:

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


Steps:

  1. Create a new Transformation.java class as shown in https://sourcegraph.com/android.googlesource.com/platform/frameworks/base/-/blob/core/java/android/view/animation/Transformation.java.

  2. Initialize a Transformation object:

    private Transformation myTransformation;
    mTransformation = newTransformation();
    
  3. Using your code:

    AnimationfadeOut=newAlphaAnimation(1, 0);
    fadeOut.setInterpolator(newDecelerateInterpolator());
    fadeOut.setDuration(350);
    
  4. Get the time at which the drawing of the view hierarchy started (in milliseconds):

    finallong time = myView.getDrawingTime();
    
  5. Get the transformation to apply at a specified point in time. Finally, obtain the actual alpha value during the animation:

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

Resources: https://sourcegraph.com/android.googlesource.com/platform/frameworks/base/-/blob/core/java/android/widget/ProgressBar.java#L1699https://developer.android.com/reference/android/view/animation/Animation.htmlhttps://developer.android.com/reference/android/view/animation/Transformation.html

Post a Comment for "Android - Getalpha() From Animated View"