属性动画

1.alpha 渐变透明度动画效果
2.scale 渐变尺寸伸缩动画效果
3.translate 画面转换位置移动动画效果
4.rotate 画面转移旋转动画效果

动态

显示动画

mShowAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,

Animation.RELATIVE_TO_SELF,-1.0f, Animation.RELATIVE_TO_SELF, 0.0f);

mShowAction.setDuration(500);

隐藏动画

mHiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0.0f, Animation.RELATIVE_TO_SELF, 0.0f,

Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,-1.0f);

mHiddenAction.setDuration(500);

View的显示:
view.startAnimation(mShowAction);
view.setVisibility(View.VISIBLE);

View的隐藏:
view.startAnimation(mHiddenAction);
view.setVisibility(View.GONE);

animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {} //在动画开始时使用

@Override
public void onAnimationRepeat(Animation arg0) {} //在动画重复时使用

@Override
public void onAnimationEnd(Animation arg0) {
Toast.makeText(AlphaActivity.this, "在动画结束时使用", Toast.LENGTH_SHORT).show();
}
});

XML

我们可以看下ImageView的显示:
ImageView imageView = (ImageView)findViewById(R.id.imageView1);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.fade_in);
imageView.setBackgroundResource(R.drawable.t);
imageView.startAnimation(animation);

 anim/alpha.xml(渐变动画)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="3000"/>
<!-- 透明度控制动画效果 alpha
浮点型值:
fromAlpha 属性为动画起始时透明度 0.0表示完全透明
toAlpha 属性为动画结束时透明度 1.0表示完全不透明
以上值取0.0-1.0之间的float数据类型的数字

长整型值:
duration 属性为动画持续时间 以毫秒为单位
-->
</set>

anim/scale.xml(伸缩动画)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="0.0"
android:toXScale="1.4"
android:fromYScale="0.0"
android:toYScale="1.4"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false"
android:duration="700" />
</set>
<!-- 尺寸伸缩动画效果 scale
属性:interpolator 指定一个动画的插入器
在试验过程中,使用android.res.anim中的资源时候发现
有三种动画插入器:
accelerate_decelerate_interpolator 加速-减速 动画插入器
accelerate_interpolator 加速-动画插入器
decelerate_interpolator 减速- 动画插入器
其他的属于特定的动画效果
浮点型值:
fromXScale 属性为动画起始时 X坐标上的伸缩尺寸
toXScale 属性为动画结束时 X坐标上的伸缩尺寸

fromYScale 属性为动画起始时Y坐标上的伸缩尺寸
toYScale 属性为动画结束时Y坐标上的伸缩尺寸

说明:以上四种属性值
0.0表示收缩到没有
1.0表示正常无伸缩
值小于1.0表示收缩
值大于1.0表示放大

pivotX 属性为动画相对于物件的X坐标的开始位置
pivotY 属性为动画相对于物件的Y坐标的开始位置

说明: 以上两个属性值 从0%-100%中取值
50%为物件的X或Y方向坐标上的中点位置

长整型值:
duration 属性为动画持续时间 以毫秒为单位

布尔型值:
fillAfter 属性 当设置为true ,该动画转化在动画结束后被应用
-->

anim/translate.xml(移动动画)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="30"
android:toXDelta="-80"
android:fromYDelta="30"
android:toYDelta="300"
android:duration="2000"/>
<!-- translate 位置转移动画效果
整型值:
fromXDelta 属性为动画起始时 X坐标上的位置
toXDelta 属性为动画结束时 X坐标上的位置
fromYDelta 属性为动画起始时 Y坐标上的位置
toYDelta 属性为动画结束时 Y坐标上的位置
注意:
没有指定fromXType toXType fromYType toYType 时候,
默认是以自己为相对参照物
长整型值:
duration 属性为动画持续时间 以毫秒为单位
-->
</set>

anim/rotate.xml(旋转动画)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromDegrees="0"
android:toDegrees="+350"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000" />
<!-- rotate 旋转动画效果
属性:interpolator 指定一个动画的插入器
在试验过程中,使用android.res.anim中的资源时候发现
有三种动画插入器:
accelerate_decelerate_interpolator 加速-减速 动画插入器
accelerate_interpolator 加速-动画插入器
decelerate_interpolator 减速- 动画插入器
其他的属于特定的动画效果

浮点数型值:
fromDegrees 属性为动画起始时物件的角度
toDegrees 属性为动画结束时物件旋转的角度 可以大于360度

说明: 当角度为负数——表示逆时针旋转
当角度为正数——表示顺时针旋转
(负数from——to正数:顺时针旋转)
(负数from——to负数:逆时针旋转)
(正数from——to正数:顺时针旋转)
(正数from——to负数:逆时针旋转)

pivotX 属性为动画相对于物件的X坐标的开始位置
pivotY 属性为动画相对于物件的Y坐标的开始位置

说明: 以上两个属性值 从0%-100%中取值
50%为物件的X或Y方向坐标上的中点位置

长整型值:
duration 属性为动画持续时间 以毫秒为单位
-->
</set>

原文地址:https://www.cnblogs.com/hui413027075/p/6500584.html