Android transition animation API 19 and above - android

I'm quite new to animation transition. I want to add an animation in the home screen. I don't know which way to go, is Lottie fit for this or official android libraries.
The animation take about 2-3 seconds and should animate every time I go to that specific screen. Please help, some explanations would be great Here's some screenshots:

You can use ObjectAnimator and AnimatorSet.
Translate that blocks to bottom in order and with some delay.
The code you need is something like that:
ObjectAnimator translateAnimator1 = ObjectAnimator.ofFloat(view1, "translationY", 0, 500).setDuration(2500);
ObjectAnimator translateAnimator2 = ObjectAnimator.ofFloat(view2, "translationY", 0, 500).setDuration(2500);
translateAnimator2.setStartDelay(500);
ObjectAnimator translateAnimator3 = ObjectAnimator.ofFloat(view3, "translationY", 0, 500).setDuration(2500);
translateAnimator3.setStartDelay(1000);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.play(translateAnimator1).with(translateAnimator2).with(translateAnimator3);
animatorSet.start();
ObjectAnimator and AnimatorSet has some extra properties like setRepeatCount etc. that maybe useful.

Related

Android Animations on button click to display other buttons with fade-in and translate animation programmatically

I want to display a buttons with animations like fade-in along with the translate animation programmatically. I have to start translate animation from a specific position on the screen. So i need to pass the x and y values for the translate animation to start from.
Im using the following code for translate animation but how to add fade-in animation to the existing translate animation?
TranslateAnimation tanim = new TranslateAnimation(
TranslateAnimation.ABSOLUTE, getIntent().getFloatExtra("ButtonX", maxX),
TranslateAnimation.ABSOLUTE, 0,
TranslateAnimation.ABSOLUTE, getIntent().getFloatExtra("ButtonY", 0),
TranslateAnimation.ABSOLUTE, 100);
tanim.setDuration(3000);
I've used Animations several times before and they always left me scratching my head. Some things I would recommend you should look into are Object Animators and Animator Sets. They're really useful, as they allow you to animate any property of the given view. As long as the view has a setter method for that property, you can add it to the animator set by passing in the string name of the property to the Animator constructor. The AnimatorSet class also allows you to easily choreograph multiple animations.
In your case, you could do something roughly like the following:
AnimatorSet animations = new AnimatorSet();
Animator xAnim = ObjectAnimator.ofFloat(button, "translationX", finalXValue);
xAnim.setDuration(3000);
Animator yAnim = ObjectAnimator.ofFloat(button, "translationY", finalYValue);
yAnim.setDuration(3000);
Animator alphaAnim = ObjectAnimator.ofFloat(button, "alpha", finalAlphaValue);
alphaAnim.setDuration(alphaDuration);
//Play all the animations together
animations.play(xAnim).with(yAnim).with(alphaAnim);
You can string together as many animators as you want this way, and you can also set animators to be played in a sequence using the .before() and .after() methods rather than the .with() method.

moving and rotating view in android

I'm using this code to moving view from x Position to another x Position :
int xStart=100,xEnd=500;
ObjectAnimator objectAnimator= ObjectAnimator.ofFloat(view, "translationX", xStart, xEnd);
objectAnimator.setDuration(duration);
objectAnimator.start();
but i need moving and rotating .
how can Rotate and move the view together ?
It is possible ?
You can use ObjectAnimator to animate any property of a View- essentially any property with set___() and get___() methods.
For rotation, you can use "rotation", "rotationX", and "rotationY" as appropriate.
It sounds like you already have translation working correctly, so I'm not sure what else you are looking for in "moving" the View.
To play multiple animations together, you can use an AnimatorSet. To move and rotate at the same time, you might do this:
AnimatorSet animations = new AnimatorSet();
ObjectAnimator translationAnim= ObjectAnimator.ofFloat(view, "translationX", 100, 500);
ObjectAnimator rotationAnim = ObjectAnimator.ofFloat(view, "rotation", 0, 90);
animations.play(rotationAnim).with(translationAnim);
animations.start();
For more information see the Property Animation documentation.

ImageView not reseting to original location after animation

I have a swipe recognizer that calls this function when a swipe is detected. The alpha animation works great, but after the animation, the image is not resetting to its original location in the center.
Currently, the image stays on the left.... I've searched all over and it seems that I'm implementing the animation correctly.
I'm using a RelativeLayout and swipeImageView is an empty imageview in the middle of my layout.
swipeImageView.bringToFront();
swipeImageView.setImageDrawable(getResources().getDrawable(R.drawable.skip4x));
ObjectAnimator nextGroupLeft = ObjectAnimator.ofFloat(swipeImageView, "x", -250f);
nextGroupLeft.setDuration(1000);
ValueAnimator fadeAnim = ObjectAnimator.ofFloat(swipeImageView, "alpha", 1f, 0f);
fadeAnim.setDuration(1000);
AnimatorSet animSetXY = new AnimatorSet();
animSetXY.playTogether(nextGroupLeft, fadeAnim);
animSetXY.start();
Trying clearing the animations. When this line is executed, the animations should stop and the ImageView should return to its original state.
swipeImageView.clearAnimation();

How to keep the process in a simple animation with some time duration?

I want to change the imageview (x,y) values by using the setX(),setY(). It is directly going like an visible/gone. I just wants to keep this in a small animation so that it will go slowly to the given cordinates.
Is there any basic animation for performing this.
You should use ObjectAnimator and AnimatorSet to achieve this.
Use Following code:
ObjectAnimator oaX = ObjectAnimator.ofFloat(view, "translationX", 0, xValue);
oaX.setDuration(1000);
ObjectAnimator oaY = ObjectAnimator.ofFloat(view, "translationY", 0, yValue);
oaY.setDuration(1000);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(oaX, oaY);
animatorSet.start();
pass your coordinate values to xValue and yValue, these are relative to your image's actual coordinates.
The easiest way to move your imageview is here:
imageview.animate().translationX(imageview.getWidth()).setDuration(1000).setInterpolator(new AccelerateDecelerateInterpolator());

How can I use an animation at the end of another animation

I am using following code for rotating an image
RotateAnimation anim1 = new RotateAnimation(0, 360, 8, 70);
anim1.setRepeatCount(0);
anim1.setDuration(18000);
anim1.setFillAfter(true);
img7.startAnimation(anim1);
After that I am using another animation
RotateAnimation anim1 = new RotateAnimation(360, 0, 8, 70);
anim1.setRepeatCount(0);
anim1.setDuration(18000);
anim1.setFillAfter(true);
img7.startAnimation(anim1);
When I am using both the animations without any action listener one of them will work....What I actually want, is at the end of the first animation, for the second animation to start...Can anybody help me to do this?
I am not using any XML code for animation.
Why won't you use Animation.AnimationListener for the first animation (setAnimationListener()) and launch the second when the first one finishes?
I think AnimatorSet was designed for this. Demo in the sdk.

Categories

Resources