apksherlock
apksherlock

Reputation: 8371

How do i apply fade out animation from left to right in android

I am trying to make a fade out animation to a View, but I don't want the standard one. I want the fade out to start from left to right (or right to left no matter). Any idea on how to do it? I didn't really found anything for android on SO. This is my code for the moment:

val fadeOut = AlphaAnimation(1f, 0f)
            fadeOut.interpolator = AccelerateInterpolator()
            fadeOut.duration = 3000L

            fadeOut.setAnimationListener(object : Animation.AnimationListener {
                override fun onAnimationStart(animation: Animation) {

                }

                override fun onAnimationEnd(animation: Animation) {
                   mTextView.visibility = View.VISIBLE
                }

                override fun onAnimationRepeat(animation: Animation) {}
            })

            mTextView.startAnimation(fadeOut)

Upvotes: 0

Views: 1404

Answers (2)

Chrisvin Jem
Chrisvin Jem

Reputation: 4060

From what I can understand, it sounds like you want a reveal animation rather than a fade in/out animation. Your best bet would be to write your own reveal Animation, but if you're ready to settle for a simpler hack, then you could use the circular reveal animation that's available in ViewAnimationUtils. Just start the circular far off to the left/right so that the circular reveal feels like a linear reveal.

final View myView = findViewById(R.id.animatedImageView);

int cx = myView.getMeasuredWidth() * 2;
int cy = myView.getMeasuredHeight() / 2;
int finalRadius = (int) Math.hypot(myView.getWidth()*2, myView.getHeight());

Animator anim;
// for reveal
anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
// for hiding
// anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, finalRadius, 0);

// Do note that you'll need to factor in the 'reveal' time taken in by the extra empty space.
// You could probably get around this by creating your own interpolator, 
// but in which case, you might as well just create your own reveal animation.
anim.setDuration(3000);

// make the view visible and start the animation
myView.setVisibility(View.VISIBLE);
anim.start();

Upvotes: 1

Deepak
Deepak

Reputation: 197

Try this:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">
    <alpha
        android:duration="1000"
        android:fromAlpha="0.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:toAlpha="1.0" />
    <translate
        android:fromXDelta="100%p" android:toXDelta="0"
        android:duration="500" />
</set>

Upvotes: 0

Related Questions