Android tween animation blinks fast and doesn't work - android

I am trying to make a TextView scale and fade out. My TextView is inside a layout file that is included into my activity's layout with
<include android:id="#+id/hud" layout="#layout/hud" android:layout_alignParentBottom="true"/>
Now, I can apply a scale animation from within the Java code like this:
TextView multiplier = (TextView)findViewById(R.id.hudMultiplier);
ScaleAnimation s = new ScaleAnimation(1.0f, 3.0f, 1.0f,3.0f);
s.setDuration(5000);
multiplier.startAnimation(s);
And it works nicely, but I want that animation (and a bunch of others) from an xml file. So I made this file:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://shemas.android.com/apk/res/android"
android:shareInterpolator="false">
<scale
android:pivotX="50%"
android:pivotY="100%"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="10.0"
android:toYScale="10.0"
android:duration="5000"
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.1"
android:duration="2000"
android:startOffset="2000">
</alpha>
</set>
I am trying to apply the animation with this code:
TextView multiplier = (TextView)findViewById(R.id.hudMultiplier);
AnimationSet an = (AnimationSet) AnimationUtils.loadAnimation(getApplicationContext(), R.anim.multiplier);
multiplier.startAnimation(an);
What happens now is that the TextView blinks for a fraction of a second and nothing actually happens.
I've tried:
removing the alpha animation - no change
removing the start offset - no change
change the animation with one from the android documentation - no change
change AnimationSet to Animation - no change
change getApplicationContext() to this, MyActivity.this - no change
change getApplicationContext() to null - kills the application
What am I missing?
The project is targeted at Android 1.6 and I'm testing in a 2.3 emulator.

This seems to make a difference, for me anyway!
Change shemas to schemas in the Set element.
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://shemas.android.com/apk/res/android"
android:shareInterpolator="false">

try this:
an = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);

Related

Android Animation to be done from bottom towards up but will be invisible in center

http://framerjs.com/examples/preview/#carousel-onboarding.framer like this i have to develop,please check this link only on Chrome .
What I'd do is an Animation Resource File (a file in the res>anim directory of your project. If you don't have the anim directory you can simply create it.).
The content of this file (named as you wish, like myanimation.xml) should be:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0" />
<translate
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="0"
android:toYDelta="-50" />
</set>
The tag means that the object will animate from completely opaque (1.0) to completly trasparent (0.0)
The tag means that the object will animate from its starting position to the same X coordinate and 50 pixels above.
To use this animation from an Activity simply use:
Animation myAnimation = AnimationUtils.loadAnimation(this, R.anim.myanimation);
myAnimation.setDuration(millisecYouWant);
viewIWantToAnimate.startAnimation(myAnimation);
for more complex animations look at this link: http://developer.android.com/guide/topics/resources/animation-resource.html
EDIT: I think the question should have more details, in this case something like the piece of code where you want to applicate this animation, or what you want to animate (like an ImageView, or a Layout ...)

Android - animate View object - specific XML <set>

I'm new to Android application programming, and using search i've so far solved all of my problems (stackoverflow being one of the best search hits !)
Now i have a problem i don't know how to solve :
When separate animations are required, i could do it in code, but using XML files in anim folder would be much better for me.
Is it possible to play an animation of a single <set> inside XML file ?
I mean is it possible to "compress" animations from mulitple XML files into one file and still use them individually ?
Example for normal animation of TextView widget :
TexView exampleTextView = (TextView) findViewById (R.id.example_textview);
Animation animatorSequence = AnimationUtils.loadAnimation (this, R.anim.example_animation);
exampleTextView.startAnimation (animatorSequence);
XML code with two example blocks that i would like to use separately
<?xml version="1.0" encoding="utf-8"?>
<!--first independant animation segment -->
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<translate
android:fromXDelta="-100%"
android:toXDelta="0%"
android:duration="1400" />
</set>
<!--second independant animation segment -->
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<translate
android:fromXDelta="0%"
android:toXDelta="100%"
android:duration="1400" />
</set>
You can't.
But you can divide them to multiple files, load the in run time and add them all to a single AnimationSet (You can also define the empty set itself in a XML file so you won't have to configure it programmatically).

Android Alpha Fade in Animation Issue

I have an ImageView element that I create in my code and place inside of my RelativeLayout. I set this image to be Invisible to start off with using the following code:
arrow.setVisibility(View.INVISIBLE);
I then defined a Fade-In Alpha animation via XML:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:fillEnabled="true"
android:fillAfter="true"
android:fillBefore="true">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:startOffset="100"
android:duration="300" />
/set>
To run the animation:
I simply call the following to start the animation
myview.startAnimation(myanimation);
The issue I am seeing is that my animation causes the ImageView to flicker in at full visibility and then go through the animation of alpha 0 to 1. How do I fix this? I can't set the initial alpha value to 0 because the alpha animation is based on percentage and not absolute alpha value. (ex: 0*current value to 1*current value)
Any help would be greatly appreciated.
I think the problem is, with this line of code:
android:fillBefore="true"
Here, Try this code instead, it works for me :
<?xml version="1.0" encoding="UTF-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fillAfter="true"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
If you are using animateLayoutChanges in your layout file in combination with the animation, toggling the View visibility will result in two animations running and the view flashing or blinking. Setting view visibility causes the layouts animateLayoutChanges to run and to fade the view in once and then the animation you created causes a second animation to run as well.

Fade animation - not constant behavior Android

I want to make a Fade Out and In Animation every time I click a button.
I started to check only the fade out and on the first click it seems the Fade Out works just fine. But when I click again the animation fade from top to bottom, making it look bad and cut.
The Animation:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1.0"
android:toAlpha="0.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:duration="1000" />
</set>
The Code:
Animation fadeOut = AnimationUtils.loadAnimation(myActivity.this, R.anim.fade_out);
LinearLayout myBackground=(LinearLayout)findViewById(R.id.myBackground);
myBackground.setAnimation(fadeOut);
What am I missing? Thanks!
Make anim in following folder ris->anim->fade_anim.xml
Add below xml
<alpha
android:duration="2000"
android:fromAlpha="1"
android:toAlpha="0.0"
android:repeatCount="infinite"/>
Got to java class
//make animation object
final Animation myAnim = AnimationUtils.loadAnimation(getContext(), R.anim.bounce_anim);
myAnim.setRepeatMode(Animation.INFINITE);
//get View on which on you want to apply animation I am applying on imageView
mLayout.findViewById(R.id.imageView).startAnimation(myAnim);

Android - Animation offset - How to prevent the view from being drawn while the offset has not yet passed?

I am trying to start an animation AFTER 1 second. I have used the attribute "android:startOffset" in my XML file, but it does not work completely the way I expected. I was expecting the view to NOT EVEN BE DRAW in its initial position (that is, the position set in the attributes "fromXDelta" and "fromYDelta") before the offset I set has passed. Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="sequentially"
android:shareInterpolator="false" >
<translate
android:duration="2000"
android:startOffset="1000"
android:fromXDelta="-70%p"
android:fromYDelta="0%p"
android:interpolator="#android:anim/linear_interpolator"
android:toXDelta="+0%p"
android:toYDelta="0%p" />
</set>
If I try to move my view using the above animation, the view is drawn IMMEDIATELY at the position -70% of the screen. Then the one second passes and then, as expected, the animation kicks in and starts to move the view. However, I DO NOT want the view to be drawn at all before that 1 second!. How can I achieve this?
Thank you in advance.
UPDATE
I am calling the above XML just after a startActivity call (the *R.anim.animation_coming_in* below), like this:
startActivity(new Intent(this, ThankYouActivity.class));
overridePendingTransition(R.anim.animation_coming_in, R.anim.animation_coming_out);
You could try using a pair of alpha animations with very short duration so that the view is hidden until it's needed. Something like this:
<set ...>
<alpha
android:fromAlpha="0.0"
android:toAlpha="0.0"
android:duration="1"
android:startOffset="0" />
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="1"
android:startOffset="1000" />
<translate
...
/>
</set>
Alternatively, you could implement this set of animations in code. Doing so would enable you to use a Handler to start the animation after a delay so that the view is hidden until the animation starts.

Categories

Resources