Reputation: 5743
I have a view. I will set the view left out of the screen. Now I want to animate a slide from left to the screen on this view. How can do this in Android?
This is my View
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/mView"
android:layout_width="200dp"
android:layout_height="140dp"
android:layout_gravity="center_vertical|end">
Upvotes: 2
Views: 1637
Reputation: 66
You can check this tutorial about animations https://github.com/codepath/android_guides/wiki/Animations
Here is the example code to move a textview in x-axis 100 points. You can animate your own view like this.
ObjectAnimator animation = ObjectAnimator.ofFloat(textView, "translationX", 100f);
animation.setDuration(1000);
animation.start();
Upvotes: 0
Reputation: 1508
This is the sample code for move a textview with animation from x position as 0 to centre of the screen width.
ObjectAnimator textViewAnimation= ObjectAnimator.ofFloat(textView,"X",0f,width/2);
textViewAnimation.setDuration(2000);
textViewAnimation.start();
Upvotes: 1