[英]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?
如何在 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">
This is the sample code for move a textview with animation from x position as 0 to centre of the screen width.这是将带有动画的文本视图从 x 位置为 0 移动到屏幕宽度中心的示例代码。
ObjectAnimator textViewAnimation= ObjectAnimator.ofFloat(textView,"X",0f,width/2);
textViewAnimation.setDuration(2000);
textViewAnimation.start();
You can check this tutorial about animations https://github.com/codepath/android_guides/wiki/Animations您可以查看有关动画的本教程https://github.com/codepath/android_guides/wiki/Animations
Here is the example code to move a textview in x-axis 100 points.这是在 x 轴 100 点上移动文本视图的示例代码。 You can animate your own view like this.
您可以像这样为自己的视图设置动画。
ObjectAnimator animation = ObjectAnimator.ofFloat(textView, "translationX", 100f);
animation.setDuration(1000);
animation.start();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.