上一节介绍了AlphaAnimation动画的用法,本节将介绍另一种形式的动画-TranslateAnimation(位移动画)。
public class
TranslateAnimation
extends Animation
java.lang.Object
↳ android.view.animation.Animation
↳ android.view.animation.TranslateAnimation
位移动画也是Animation类的子类,常用构造方法如下:
TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)。有四个参数:
fromXDelta:起始X坐标
toXDelta: 结束X坐标
fromYDelta:起始Y坐标
toYDelta: 结束Y坐标
同样可以通过两种方式实现位移动画,通过实例进行演示。
代码方式实现
1.主布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="demo.androidwar.com.translatedemo.MainActivity">
<Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="ce

本文详细介绍了Android中的TranslateAnimation,它是Animation类的子类,用于实现位移动画。通过代码和XML两种方式展示了如何创建和使用TranslateAnimation,并强调了fillAfter属性在XML中的正确使用以保持动画结束状态。
最低0.47元/天 解锁文章
1030

被折叠的 条评论
为什么被折叠?



