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);
}
});
Related
I try to do a menu with a hide button. When I press the hide button, i do objectAnimator= ObjectAnimator.ofFloat(myLayout, "translationY"... to move the layout up.
My problem is when I move all the layout up, it didn't grow, it only move up with his fixed size. I don't know how to refresh the size of the layout to match_parent so my 2nd layout will take all the place.
Thanks
Kick off example:
ObjectAnimator anim = ObjectAnimator.ofFloat(myLayout, "translationY"...);
anim.addListener(new AnimatorListener() {
#Override
public void onAnimationEnd(Animator animation) {
((RelativeLayout.LayoutParams) view.getLayoutParams).width = ViewGroup.LayoutParams.MATCH_PARENT;
}
});
I think you can't achive this effect using only translation. Translating object still keep its bounds in layout (you can see it when you turn on Developer options -> Show layout bounds on your device). It's just drawing in a different place.
I don't know what you exactly want to do, so if that tip is not enough, try to give more details. For now I can only propose animating one of your views' height.
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 need to display an image button that fades in and out (and in and out and so on...)
The transparency can be set with setAlpha but how can I fade in and out? I mean I cannot do it on another thread because you need to do such things on the UI thread, right?
I guess it can be done with animations but I haven't found anything, because I don't have any experience with animations and don't really know what to search for...
Actually what I really want is to fade one image in and another one out but I guess the easiest way is to place the first image button below the second and just fade the second one. Or is there an easier way to do it?
Here is the solution I'm using now, that works on API level lower than 12:
AlphaAnimation anim = new AlphaAnimation(1.0f, 0.0f);
anim.setDuration(1000);
anim.setRepeatCount(NUM_REPEATS);
anim.setRepeatMode(Animation.REVERSE);
button.startAnimation(anim);
This is an animation we used in our project. Spinner is a view so you can change this with your imageview. So indeed 2 images on top of eachother, one visible one invisible. This is how we did it. Hope it helps.
spinner.setVisibility(View.VISIBLE);
spinner.setAlpha(0);
spinner.animate().setDuration(200).alpha(1).setListener(new AnimatorListenerAdapter() {
#Override
public void onAnimationEnd(Animator animation) {
spinner.setVisibility(View.VISIBLE);
}
});
infoActivityContent.animate().setDuration(200).alpha(0).setListener(new AnimatorListenerAdapter() {
#Override
public void onAnimationEnd(Animator animation) {
infoActivityContent.setVisibility(View.GONE);
mainPresenter.logout();
}
});
You have to read Crossfading Two Views from Android developers. In this tutorial is explained how to do what you want.
in kotlin:
view.animate().alpha(1f).setDuration(1000)
.setInterpolator(AccelerateInterpolator()).start()
You can add an AnimatorListenerAdapter in setListener to handle other view states.
You can make several sequential frames of your first image morphing into your second image and back, then define them as animation-list and start animation in onCreate
button_frames.xml:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/frame1" android:duration="100" />
<item android:drawable="#drawable/frame2" android:duration="100" />
....
layout:
<ImageView android:id="#+id/button"
android:background="#drawable/button_frames"/>
OnCreate:
ImageView button= (ImageView)findViewById(R.id.button);
mAnimation = (AnimationDrawable) animationView.getBackground();
button.postDelayed(new Runnable() {
public void run() {
mAnimation.start();
}
}, 100);
Implement Animation Class ( You can load it thru XML Or create it dynamically).
Then you can set it thru API setAnimation(Animation animation).
I have an Android application with some ImageButtons, just like icons.
I would like to know how I could implement a function to "shake" icons after user long-presses them. Like iPhone icons on edit mode, you know?
After editing, icons stop shaking.
Is it possible to do that in Android?
use this to start the shaking animation on your icons upon the long press event of your button
public void onClick(View v) {
Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
findViewById(R.id.pw).startAnimation(shake);
}
This snippet is taking from the android API Demo here http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/Animation1.html
Try to use TranslateAnimation (And/Or AnimationSet) on the button.
something like this:
private void onYourButtonLongPress()
{
TranslateAnimation animation = new TranslateAnimation(0, -5, 0, 0);
animation.setDuration(100):
yourButton.startAnimation(animation);
}
notice that this example is only for shake to left
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).