微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android 动画基础绘——view 动画

前言

对android 动画的整理,android 动画分为view动画(也叫补间动画),帧动画,属性动画。
看到这几个概念,让我想起了flash这东西。如果需要查各种动画具体的含义,那么可以去查询flash,flash资料对这一块介绍非常详细。
在这里简单介绍view动画:

  1. 平移动画
  2. 缩放动画
  3. 旋转动画
  4. 透明动画

就这几个概念而言,具体看下是什么操作。

正文

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:Interpolator="@[package:]anim/interpolator_resource"
    >
    <alpha
        android:fromAlpha="0.8"
        android:toAlpha="1.0"
        >
    </alpha>
    <scale
        android:fromXScale="0.5"
        android:toXScale="1.5"
        android:fromYScale="0.5"
        android:toYScale="1.5"
        >
    </scale>
    <translate
        android:fromXDelta="50"
        android:toXDelta="100"
        android:fromYDelta="50"
        android:toYDelta="100"
        >
    </translate>
    <rotate
        android:fromdegrees="40"
        android:todegrees="100"
        android:pivotX="50"
        android:pivotY="100"
        >
    </rotate>
</set>

介绍属性
set 标签属性:android:Interpolator 表示插入器,就是来表示我这个运动是怎么运行的,是先快后慢呢,还是先慢后快。
认是先快后慢,下面是标签对应的:


set标签属性:shareInterpolator 表示是否共享插入器,下面有旋转,透明度变化等,这个就是设置他们的变化是否一致。
如果设置为false,就需要在每一个子动画中加入:android:Interpolator="@[package:]anim/interpolator_resource"。
例如:

<scale
android:interpolator="@android:anim/linear_interpolator"
android:fromXScale="0.5"
android:toXScale="1.5"
android:fromYScale="0.5"
android:toYScale="1.5"
>

set 还有其他一些常用的属性:
android:fillAfter="true" 表示是否动画结束后,是否停留到动画结束的位置。
android:duration: 动画持续时间
至于具体的里面的动画属性就很好理解了。
元素如何绑定动画:

  Button button=(Button) findViewById(R.id.test);
  Animation animation= AnimationUtils.loadAnimation(this
  ,R.anim.test);
  animation.setAnimationListener(new Animation.AnimationListener() {
	@Override
	public void onAnimationStart(Animation animation) {
	  
	}

	@Override
	public void onAnimationEnd(Animation animation) {

	}

	@Override
	public void onAnimationRepeat(Animation animation) {

	}
  });
  button.startAnimation(animation);

创建动画资源,然后和animation 绑定即可。
可以在动画开始,重复和结束的时候增加监听。
同样,我们不一定要写在xml中:

Button button=(Button) findViewById(R.id.test);
Animation animation = new AlphaAnimation(0,1);
animation.setDuration(200);
button.setAnimation(animation);

上面是设置透明的。
这时候是和上面写的xml不同的,怎么只有一个啊,比如说又要透明又要缩放。

Button button=(Button) findViewById(R.id.test);
AnimationSet animationSet=new AnimationSet(true);
animationSet.setDuration(200);
Animation animationScale=new ScaleAnimation(0,1,0,1);
Animation animationAplph = new AlphaAnimation(0,1);
animationSet.addAnimation(animationScale);
animationSet.addAnimation(animationAplph);
button.setAnimation(animationSet);

new AnimationSet(true) 这个true的意思,是让他们共享一个插入器的意思。

总结

还有自定义view动画,因为涉及到矩阵,相对麻烦,而且基本用不上就不介绍了。
后续写一个插入器的总结。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐