dudi
dudi

Reputation: 5743

How to animate a slide from left on a View in Android

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

Answers (2)

Juan Rodr&#237;guez
Juan Rodr&#237;guez

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

jeevashankar
jeevashankar

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

Related Questions