Android textView animation at the same time - android

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

Related

Can I rotate a spinner? Androidstudio

simple question I cant find the answer anywhere, is there a way to rotate a spinner, without rotating screen or anything just create a spinner which is rotated 90 degrees?
Thanks in advance.
On API Level 11+, you are welcome to rotate any View via android:rotation in your layout XML or setRotation() in Java. Whether this will give you something that your users will like, I cannot say.
Programmatically you can try something like this -
RotateAnimation animation = new RotateAnimation(fromDegrees, toDegrees, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
// Adding the time needed to rotate the image
animation.setDuration(250);
// Set the animation to stop after reaching the desired position. Without this it would return to the original state.
animation.setFillAfter(true);
//Then set the animation to your view
view.startAnimation(animation);

AlphaAnimation in android

I am implementing an AlphaAnimation in my android project with the below line code, but I am unsure how it works and what goes in the parameters.
AlphaAnimation buttonClick = new AlphaAnimation(1F, 0.1F);
What is the first parameter for and what what values can I put in it?
What is the second parameter for and what values can I put in it?
Is it possible to have more then 2 parameters?
Can someone please help me out?
AlphaAnimation is for fading in / out view.
As per documentation
Parameters:
fromAlpha : Starting alpha value for the animation, where 1.0 means fully opaque and 0.0 means fully transparent.
toAlpha : Ending alpha value for the animation.
So if you use
AlphaAnimation buttonClick = new AlphaAnimation(0.0f, 1.0f);
It will mean opacity will be 1 at the end of animation.
Whereas, for fading out image from visible to invisible, you can use
AlphaAnimation buttonClick = new AlphaAnimation(1.0f, 0.0f);
Hope this helps.

Android Image View Animation leaving behind trail

I am animating an ImageView from the center of the screen to the top-left using an Animation Set.I am Translating and Scaling the View.
Heres the code snippet.
AnimationSet tempAnimation=new AnimationSet(true);
TranslateAnimation anim = new TranslateAnimation( 0,xPos, 0, yPos );
anim.setFillAfter( true );
anim.setFillEnabled(true);
ScaleAnimation scaleanimation = new ScaleAnimation(1, (float)0.22, 1, (float)0.22, Animation.RELATIVE_TO_SELF, (float)0.5, Animation.RELATIVE_TO_SELF, (float)0.5);
scaleanimation.setDuration(1000);
scaleanimation.setFillEnabled(true);
scaleanimation.setFillAfter(true);
tempAnimation.addAnimation(scaleanimation);
tempAnimation.addAnimation(anim);
tempAnimation.setDuration(1000);
// This takes care that the ImageViews stay in their final positions after animating .
tempAnimation.setFillEnabled(true);
tempAnimation.setFillAfter(true);
mimageView.startAnimation(tempAnimation);
So,the problem is that it is leaving behind a trail /previous positions for just a brief moment.But it doesnt look good or smooth.I have noticed that if I use only 1 animation it is fine but using the animation set causes the trail.Are there any tips to avoid this?
Cheers
Found the answer eventually at https://code.google.com/p/android/issues/detail?id=22151.
Scale and Translation Animations have a problem on Android 2.3 .The simplest way to fix this is to add a small transparent padding around the image.In the code shown above,Just add
mimageView.setPadding(1,1,1,1);
Works like a charm!

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

Leaving an Android Animation at it's end state

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

Categories

Resources