I want to merge animations in android application.
I'm using below code for that,but alpha animation not wrking.
I have no idea why it is not working.
// create set of animations
AnimationSet login_page_animation = new AnimationSet(false);
// animations should be applied on the finish line
login_page_animation.setFillAfter(true);
// create scale animation
int white_background_height=((TextView) findViewById(R.id.login_white_backgroud)).getHeight();
TranslateAnimation translate_animation = new TranslateAnimation(0,0,0,- white_background_height/4);
translate_animation.setDuration(700);
// create Alpha animation
AlphaAnimation alpha_animation=new AlphaAnimation(0.0f,1.0f);
alpha_animation.setDuration(700);
// add new animations to the set
login_page_animation.addAnimation(translate_animation);
login_page_animation.addAnimation(translate_animation);
Looks like you're adding translate_animation again on that last line instad of alpha_animation.
Related
Building this app, I have managed to use some animations
using them with View view.setAnimation() etc..
This is the code i have:
// animation Properties
Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setInterpolator(new DecelerateInterpolator()); // add this
fadeIn.setDuration(5000);
AnimationSet animation1 = new AnimationSet(false); // change to false
//animation.addAnimation(fadeIn);
animation1.addAnimation(fadeIn);
animation1.setRepeatCount(1);
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator()); // and this
//fadeOut.setStartOffset(fadeInDuration + timeBetween);
fadeOut.setDuration(5000);
AnimationSet animation = new AnimationSet(false); // change to false
//animation.addAnimation(fadeIn);
animation.addAnimation(fadeOut);
animation.setRepeatCount(1);
textViewTopBannerBizName.setAnimation(animation1);
textViewTopBannerBizCategory.setAnimation(animation1);
So all, I want is that textViewTopBannerBizName and textViewTopBannerBizCategory will fade into screen as i used animation1 for both of them.
However first time when i launched the app it worked perfect but when I relaunched it again it stopped working.
It makes me wonder... why...?
Please help,
Thank you for your time.
try this.(Tested)
textViewTopBannerBizName.startAnimation(animation1);
You can clear animation if cached before by calling clearAnimation() and then startAnimation or setAnimation.
Edited
setAnimation
Sets the next animation to play for this view.But view animation does not start yet.
startAnimation
If you want the animation to play immediately, use startAnimation. This method provides allows fine-grained control over the start time and invalidation, but you must make sure that
1) the animation has a start time set,
2) the view will be invalidated when the animation is supposed to start
After setting animation, Please do invalidate the view if it's not an Activity
imb6.setAnimation(MainActivity.blinkAnimation(mContext, true))
invalidate();
I wish this'll helps.
I'm using the KenBurnsView library in here
But transition is not smooth and I don't know how to use the following code noted on github:
RandomTransitionGenerator generator = new RandomTransitionGenerator(duration, interpolator);
kbv.setTransitionGenerator(generator);
Can anyone help me how to create a smooth transition?
So you already have a KenBurnsView type object i.e kvb. To add a custom transition as the docs says and you also suggest.
Make
RandomTransitionGenerator generator = new RandomTransitionGenerator(duration, interpolator);
RandomTransitionGenerator is a class already included in the lib.
It takes 2 parameters :
1) duration i.e in miliseconds (usualy that the case)
2) interpolator - it is more like the effect of animation or rate of change of an animation.
We need to make an object of type Interpolator and use it like :
AccelerateDecelerateInterpolator ACCELERATE_DECELERATE = new AccelerateDecelerateInterpolator();
RandomTransitionGenerator generator = new RandomTransitionGenerator(10000, ACCELERATE_DECELERATE);
//duration = 10000ms = 10s and interpolator = ACCELERATE_DECELERATE
kbv.setTransitionGenerator(generator); //set new transition on kbv
the docs also adds that if you need more customization you can make your own TransitionGenerator class like RandomTransitionGenerator
the image will go back to 0,0 after animation finish
how to set not go back?
still stay in 100,100
Animation am = new TranslateAnimation((float)0(), (float)100, (float)0,(float)100);
am.setDuration(5000);
am.setRepeatCount(0);
point.startAnimation(am);
Use Animation.setFillAfter(true) to persist the final animation state.
http://developer.android.com/reference/android/view/animation/Animation.html#setFillAfter(boolean)
If fillAfter is true, the transformation that this animation performed will persist when it is finished. Defaults to false if not set. Note that this applies to individual animations and when using an AnimationSet to chain animations.
Animation am = new TranslateAnimation((float)0(), (float)100, (float)0,(float)100);
am.setDuration(5000);
am.setFillAfter(true);
am.setRepeatCount(0);
point.startAnimation(am);
I am trying to set blink animation on two words so that they blink one after the other, but what ever I do only 2nd word is displayed, can any one provide me method for doing the same, I am working with API level 10 so, cannot use "Animatorset".
AnimationSet set = new AnimationSet( true );
Animation blink = new AlphaAnimation(1, 0 );
blink.setDuration(duration);
blink.setFillAfter(true);
set.addAnimation( blink );
txtvw.setText("FIRST");
txtvw.setVisibility(View.VISIBLE);
txtvw.setAnimation(blink);
AnimationSet set2 = new AnimationSet( true );
Animation blink2 = new AlphaAnimation(1, 0 );
blink2.setDuration(duration);
blink2.setFillAfter(true);
set2.addAnimation( blink );
txtvw.setText("SECOND");
txtvw.setVisibility(View.VISIBLE);
txtvw.setAnimation(blink2);
if your code is like this, your text "first" gets replaced by text "Second" immediately. And the animation is shown. This animation gives an illusion that only second is blinking. Your text first is being set for microseconds but it immediately gets replaced by second.
If you want to show both the texts, you may need to use Thread
Using two animation sets for the same animations (that is, "blinking animation") is an overkill. You may just repeat your animation 2 times. Use setRepeatCount(int) in conjunction with setRepeatMode(int) to achieve this.
If you insist on using the code you have provided in your post, you will need to specify animation offset. Animation offset indicates "how much time should animation wait before start". For example, if you have Animation a and b, and want b happen after a, you might use the code:
b.setStartOffset(a.getDuration());
Then b animation will happen just after a has finished.
I am new to android and I want to simulate a car steering wheel. I found it easy to insert an Image(of steering wheel) and use tween animation to rotate it though XML.
I measured the rotation of the phone using sensor classes in .java file.
Now I need to pass this measured value from .java file to .xml (under res\anim) so as to rotate the image as per the roation of the phone.
Kindly help me by advicing a way to do this.
It's impossible to pass calculated value to xml resource, since resources are static.
But you can load the xml animation with
Animation anim = AnimationUtils.loadAnimation(context, id)
modify its properties
and apply it to the desired view with
desiredView.startAnimation(anim);
M1shk4 and Chet Haase, as told "It's impossible to pass calculated value to xml resource"
So to implement my requirement, we need to do it using code in . Java file.
The below was the code I got from Chet Haase:
public void turn()
{
RotateAnimation anim = new RotateAnimation(currentRotation, currentRotation + 30,Animation.RELATIVE_TO_SELF, 0.5f,nimation.RELATIVE_TO_SELF,0.5f);
currentRotation = (currentRotation + 30) % 360;
anim.setInterpolator(new LinearInterpolator());
anim.setDuration(1000);
anim.setFillEnabled(true);
anim.setFillAfter(true);
turnImg.startAnimation(anim);
}
Its working fine: )
For more info