I applied an entry animation to one of my ImageButton (fade_in.xml which is in the project anim/ folder). Now, after a button click, I want to apply an exit animation (fade_out.xml which is in the same folder)
When I do that, the entry animation happens. However, the exit one do NOT !! It seems that each View will accept ONLY one animation.
Is this true? How can I work around this problem?
-
-
UPDATE:
This is in the onCreate() method for setting the entry animation:
Animation fade = AnimationUtils.loadAnimation(this, R.anim.fade_in);
fade.setStartOffset(600);
img.startAnimation(fade);
img.setvisibility(View.VISIBLE);
And this is in the onClick() method for some button b1:
Animation fade2 = AnimationUtils.loadAnimation(this, R.anim.fade_out);
fade.setStartOffset(500);
img.startAnimation(fade2);
img.setvisibility(View.INVISIBLE);
You can use ViewFlipper with getInAnimation and getOutAnimation methods.
Other solution is setting animation in your code(as far I understand you set animation in xml file).
Related
When click on button_next then linear_layout_email slide left and linear_layout_password will come from right. example https://imgur.com/a/b7b66
Here my java code paste below. please find some solution on it.
mLinearLayoutEmail.animate().translationX(-1000);
mLinearLayoutPassword.animate().translationX(-80);
To me its better to read all the animation calculate them and then go for making Xml anim for each of the anim and use it as you need using AnimationUtils!
here its done in step by step! there is a builtin method for animation.
follow the steps in the code!
FADE IN RIGHT
[![FADE IN RIGHT animation in xml anim file][1]][1]
slide left
[![ANim xml code for slide and fade left][2]][2]
using ANimationUtils.loadAnimation(context,ANimFileResource) to read the anim file
e.g
Animation FadeAnim = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fading_anim);
use StartAnimation method over the linearLayout in the ClickListener of the button you want to use for loading the anim for example
fabPostTimeLine.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mGetSwipedLeftLinLay.startAnimation(FadeAnim);
}
});
So i'm trying to do 2 animations simultaneously, one to move a textview, and one to show a linearlayout (also 2 animations to hide them). I have another animation working as intended to show/hide a seperate layout. When i execute showing the view with 2 animations, it works once, it hides fine, but then doesn't work again. Then when i show the other view, it plays all 3 animations (not intended). I can't figure out why this is happening? When i try to show the 2 animations it does nothing, but then when i try the other show view its like it was added to a queue and it shows all 3.
My code for initiating the two animations:
LinearLayout layoutMsgs = (LinearLayout)findViewById(R.id.layoutMsgs);
Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.msgs_show);
anim.setAnimationListener(new AnimListener(layoutMsgs, View.VISIBLE)); // sets visibility on animation end
layoutMsgs.startAnimation(anim);
TextView tvMsgs = (TextView)findViewById(R.id.tvMsgs);
Animation tvAnim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.tvmsgs_show);
tvMsgs.startAnimation(tvAnim);
My code for hiding the two animations:
LinearLayout layoutMsgs = (LinearLayout)findViewById(R.id.layoutMsgs);
Animation animLayout = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.msgs_hide);
animLayout.setAnimationListener(new AnimListener(layoutMsgs, View.INVISIBLE));
layoutMsgs.startAnimation(animLayout);
TextView tvMsgs = (TextView)findViewById(R.id.tvMsgs);
Animation animMsgs = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.tvmsgs_hide);
tvMsgs.startAnimation(animMsgs);
Then this is the other animation that is working fine, it's only one animation, no textView, just a layout
LinearLayout pokeLayout = (LinearLayout)findViewById(R.id.layoutPokes);
Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.poke_show);
anim.setAnimationListener(new AnimListener(pokeLayout, View.VISIBLE));
pokeLayout.startAnimation(anim);
So how can i fix this? Sorry if my explanation is bad i'm finding it difficult to explain all the details, please ask for any missing information.
solved by using solution in this post Android: Using ObjectAnimator to translate a View with fractional values of the View's dimension
wasn't pretty as I had to create seperate translate X and translate Y res files for each view I need to move.. ended up with like 15 anim files. Would still like to know if theres a better solution
I want to show a objectanimator in android for a imageview.This imageview should move from top of the screen to about 30 pixels down from top of the screen.Once it(imageview) reaches there and onclick of the imageview the image view should disappear.I have read that i cannot use translate animation as the onclick event wont get fired and hence i will have to use Objectanimator.
Can somebody please help me out in this ...stuck up for a long time now.
Following is my code i have used however it does not seem to work also i do not understand what parameters(for that points) i need to pass.
ObjectAnimator scaleXOut = ObjectAnimator.ofFloat(tv, "translationX", 1f, 9f);
AnimatorSet set = new AnimatorSet();
set.play(scaleXIn);
set.setDuration(1000);
set.start();
you can use translateAnimation and add an animationlistener so when animation ends its onAnimationEnd() method will fired up, so inside it you can put the codes that was in onclick method, or you can put an if statement inside your onclicked method to check whether animation ends, for more about animations you can check out these resources
http://www.youtube.com/playlist?list=PLxLa2tjhVPOZ9KMqanm12_xPDBjKPZWgM
and
http://www.vogella.com/articles/AndroidAnimation/article.html
I want to know how to give fade in fade out animation to android:background image. i want to use two or more images and give this animation. pls . how can I do that. in any layout..?
cheers
You have to set animation to the layout
You can provide fade_in or fad_out animation to the layout
to set fade_in to layout use the following code
Animation mAnim = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
layout.startAnimation(mAnim);
to set fade_out to layout use the following code
Animation mAnim = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);
layout.startAnimation(mAnim);
I am facing problem in getting a sequence of animation on a particular view.
I used animationset in my code and i have set the offset for each animation and the duration for the animation correctly.
somebody pls help with this.
Thanks...
To play back animations sequentially, just use the set the android:ordering property of the <set> tag to have the value "sequentially".
Then, all set items will be animated in their sequence of declaration.
For page transition use the below snippet
pageTransition(Context context, View view){
Animation mAnim = AnimationUtils.loadAnimation(context, R.anim.slide_top_to_bottom);
mAnim.setRepeatMode(Animation.ABSOLUTE);
view.startAnimation(mAnim);
}
refer the below link for more details deVogella