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);
Related
I want to have some sort of animation when user clicks an image. I tried adding Blink animation to texureView but it keeps blinking. Below is the code:
Animation animation;
mTextureView = (AutoFitTextureView)view.FindViewById(Resource.Id.texture);
animation = AnimationUtils.LoadAnimation(Activity,Resource.Animation.blink);
mTextureView.StartAnimation(animation);
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:duration="0"
android:repeatMode="reverse"
android:repeatCount="infinite"/>
</set>
I basically want a default click effect which occurs when you click an image by going to the camera app. Is there any way I can achieve this?
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.
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);
I want to have a View that initially is invisible and when I press a button, it becomes visible with a fade in animation. I'm using the AlphaAnimation for the fading effect. The problem is that if I make the view invisible the animation can't be seen.
Suppose you have an ImageView named imageView and an animation file your_fade_in_anim.xml inside your res\anim\ folder:
ImageView imageView = (ImageView) findViewById(R.id.imageView);
Animation fadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.your_fade_in_anim);
// Now Set your animation
imageView.startAnimation(fadeInAnimation);
Your XML
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:duration="[duration (in milliseconds)]"
android:repeatCount="infinite" />
</set>
Replace the brackets with your actual duration.
Provide an AnimationListener to the Animation and make the View visible as soon as the Animation starts.
http://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html
Instead of the infinite repeat count and hiding/viewing your View, I suggest to just not repeat the animation and initially start with the alpha channel set to maximum. Then you can use:
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:duration="[duration (in milliseconds)]"
android:repeatCount="0" />
</set>
And you're done. No need for a Listener, hiding or showing. Just as simple.
I'm trying to create an animation which will slide a textview out to the left and slide in again from the right. Essentially, this would be the same text effect used in the Stopwatch & Timer app (sportstracklive is the developer).
I can use either of these animation sets exclusive of the other and it works fine, does exactly what I want. But as soon as I try using them together, the TextView just blinks over the course about around 1 second. Removing the startOffset works as expected. Both animation sets run simultaneously.
Here's the XML:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0%"
android:toXDelta="-25%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="#android:integer/config_shortAnimTime"
/>
<alpha
android:interpolator="#android:anim/decelerate_interpolator"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="#android:integer/config_shortAnimTime"
/>
<set>
<translate
android:fromXDelta="25%"
android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:startOffset="#android:integer/config_shortAnimTime"
android:duration="#android:integer/config_shortAnimTime"
/>
<alpha
android:interpolator="#android:anim/decelerate_interpolator"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:startOffset="#android:integer/config_shortAnimTime"
android:duration="#android:integer/config_shortAnimTime"
/>
</set>
</set>
And here's the lengthy Java code that runs it:
AnimationSet mSlideRightToLeft =
(AnimationSet) AnimationUtils.loadAnimation(this, R.anim.slide_right_to_left);
mMyTextView.startAnimation(mSlideRightToLeft);
Justinl's comment is correct. I had the exact same problem a couple months ago. Remove the set tags around the other animations, and keep the startOffsets.
Next remove the animation set in your code and just do a normal load animation:
Animation a = AnimationUtils.loadAnimation(this, R.anim.slide_right_to_left);
mMyTextView.startAnimation(a);
Edit: Yea, it looks like Android simply doesn't like this setup when there are multiple animations at the same time. I think you might have to create separate files for each set of animations and then configure them via an AnimationSet inside your program.