zoukankan      html  css  js  c++  java
  • 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动画,因为涉及到矩阵,相对麻烦,而且基本用不上就不介绍了。
    后续写一个插入器的总结。

  • 相关阅读:
    POJ 3672 水题......
    POJ 3279 枚举?
    STL
    241. Different Ways to Add Parentheses
    282. Expression Add Operators
    169. Majority Element
    Weekly Contest 121
    927. Three Equal Parts
    910. Smallest Range II
    921. Minimum Add to Make Parentheses Valid
  • 原文地址:https://www.cnblogs.com/aoximin/p/12297901.html
Copyright © 2011-2022 走看看