Leaving an Android Animation at it's end state - android

I'm trying to do an animation that takes a button (with a custom background image and system text) and fades it out. That works fine, actually. The issue is after the animation it goes back to it's initial state. I want it to animate and stay that way.
Thanks!

AlphaAnimation anim = new AlphaAnimation(1, 0.2f);
anim.setDuration (5000);
textView.startAnimation (anim);
anim.setFillAfter(true);
That should work.
My answer is 'stolen' form android.View transparency

Related

Android: Why do Object Animators retain the start value?

I have a mixture of animations running on various scenarios.
As an example;
I have a fade-in and fade-out animator on a small circle bitmap. On ACTION_DOWN the fade-in should start
and on ACTION_UP, when the fade-in ends, fade-out should run. BUT, if the user picks up the finger before the fade-in ends, it should stop right there (fadein.cancel()), fade-out should start from THAT alpha value.
I dont want a new object animator each time, I defined an animator like this in the constructor
fadein = Objectanimator.ofFloat(bitmap, "alpha", 1.0f);
fadeOut = Objectanimator.ofFloat(bitmap, "alpha", 0.0f);
What happens is, if I produce the issue as mentioned (picking up the finger fast), the fadeout animator will pick up the alpha value where fade-in left off and it'll RETAIN that. That is, 2nd time onwards it'll NOT pick up a new alpha! Why is that? Whats the workaround? Create new objects each time?
ObjectAnimator class modifies the attributes of the view, so it updates the property of the view using the setter method of the Object property (as per official Android Guide).
So, when fadein animation runs, the alpha value is constantly modified, and when fadein.cancel() executes, the alpha value of the View stops updating. Let's say this value is X.
So, when you start fadeOut, it animates from X to 0.0f.
Whats the workaround?
For fadeOut, use two values imply a starting and ending values
fadeOut = Objectanimator.ofFloat(bitmap, "alpha", 1.0f, 0.0f);

Android RotateAnimation overlapping

working in android last couple of days and i am trying to rotate an arrow by pressing a button. Using RotateAnimation and:
setFillAfter(true);
arrow remains in last position as supposed to.
But when i press button again arrow yes starts to rotate from initial position, but there is also the "previous" arrow from the last call of animation which is finally overlapped by "new" arrow. So i guess i need to somehow reset/clear the setFillAfter but i can't find a way.
My code goes like this:
//Animation start
float Xaxis=0.835366f;
float Yaxis=0.676692f;
RotateAnimation rotateAnimation1 = new RotateAnimation(0, 180,
Animation.RELATIVE_TO_SELF, Xaxis,Animation.RELATIVE_TO_SELF, Yaxis);
rotateAnimation1.setInterpolator(new LinearInterpolator());
rotateAnimation1.setDuration(2500);
rotateAnimation1.setRepeatCount(0);
image.startAnimation(rotateAnimation1);
rotateAnimation1.setAnimationListener(this);
#Override
public void onAnimationEnd(Animation animation) {
animation.setFillAfter(true);
}
Any ideas would be usefull..
I have tried invalidate, clearAnimation to image, setting fillafter to false, reset on animation but still same.
It is fixed, emulator is configured with shared GPU and runs perfectly. Fast and without any remainings of previous animations.

Android fadeAnimation works partially

I'm trying to make an animation on a layout that has been previously rotated using RotateAnimation. The animation i want to do are fadeIn and FadeOut depending of the situation
aLayout = (LinearLayout) _context.findViewById(R.layout.layoutId);
AlphaAnimation fadeIn = new AlphaAnimation(0, 1.0f);
AlphaAnimation fadeOut = new AlphaAnimation(1.0f, 0);
fadeIn.setDuration(500);
fadeOut.setDuration(500);
fadeIn.setFillAfter(true);
fadeOut.setFillAfter(true);
Depending of the situation i apply :
aLayout.startAnimation(fadeIn);
or
aLayout.startAnimation(fadeOut);
I've check and the animations aren't trying to start at the same time. The behaviour is that my layout is partially fadeIn.
Instead of having 'invisible part' and then 'visible part'
i only got part of the layout 'invisible part' to 'in le rt'.
It seems totally random that's why i'm asking you in case you have any idea of where it can come from. Before the rotation this alpha stuff works well but once i do it i start having this unexpected behaviour
I'm working from 2.2 to 4.1 Any help would be appreciated. Thanks
Edit : Can't figure this out. Anyone ?
I use a fadeout animation using this:
public void fadeout(final View view) {
// Start Fade Animation
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setStartOffset(1000);
fadeOut.setDuration(1000);
AnimationSet animation = new AnimationSet(false);
animation.addAnimation(fadeOut);
view.startAnimation(animation);
}
and I call it in the onCreate after setting the Content view of the activity that I want to fade out after grabbing the layout root:
View layoutRoot = findViewById(R.id.splashscreen);
fadeout(layoutRoot);
As for the rotation part you can call the animation in the onConfigurationChanged
Seems it's a bug on android. Couldn't figure how to solve it.
Anyway, i found another way to do this. Instead of making the Layout rotating i rotate only the UIElement i needed to be rotate and create the element i want to animate twice. One for the vertical position the other for the horizontal one.
This is the only way i found

How do they do this? animated drawer rotation possible?

How do they do this? animated drawer rotation possible?
In the screenshots below, touching the 'Touch' circle at the bottom causes that circle to rotate around itself, and then 4 new navigation buttons come out that take me to other screens/activities in the app. I really want to have this in my app..
Is it a sliding drawer or some other strategy? BTW I am targeting android version 2.1
It looks as if it's mainly a animation that rotates an image. Once the animation has finished, the buttons are activated.
ImageView discsAndButtons = (ImageView) findViewById(R.id.discsAndButtons);
Animation anim = new RotateAnimation(0.0f, 90.0f, 0.0f, 480.0f);
anim.setDuration(600);
anim.setFillAfter(true);
anim.setAnimationListener(this);
discsAndButtons.setAnimation(anim);
...
void onAnimationEnd(Animation animation) {
ViewGroup buttonLayer = (ViewGroup) findViewById(R.id.buttonLayer);
buttonLayer.setVisibility(View.VISIBLE);
}
Visually, the buttons are part of the image. But the effective buttons are probably on a separate layer above the image and only made visible after the animation has finished (except for the TOUCH button).

Android textView animation at the same time

I want to be able to do this: the TextView to change its size (to get bigger) and to change its alpha value (from invisible to become visible). All of this using Animation and have this changes happen at the same time.
For that purpose I come up with this code:
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(2000);
animation.setStartOffset(300);
animation.setFillAfter(true);
set.addAnimation(animation);
animation = new ScaleAnimation(1.0f, 2.0f, 1.0f, 2.0f);
animation.setDuration(2000);
animation.setStartOffset(300);
animation.setFillAfter(true);
set.addAnimation(animation);
text.startAnimation(set);
The problem with this is that I want this transformation to remain. But the textView keeps coming back to its original size at the end. (But it remains visible - alpha = 1.0f). Am I doing something wrong? Please, if someone knows how can I make this work, help me. Thank u in advance!
I've found an answer for the problem five minutes after actually posting it. You should not define setFillAfter for the individual animations that you define in the animation set. You should only define setFillAfter ON the animation set itself

Categories

Resources