前言

对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动画,因为涉及到矩阵,相对麻烦,而且基本用不上就不介绍了。

后续写一个插入器的总结。

android 动画基础绘——view 动画的更多相关文章

  1. android 动画基础绘——view 动画(二)[补]

    前言 这个是对view 动画的补充,是一些view 动画的特殊使用场景. 回顾第一篇关于view 动画的,我介绍到view的动画都是针对元素本身的. 当我们开发view动画的时候,我们看到几个元素在做 ...

  2. android 动画基础绘——帧动画(三)

    前言 这篇介绍帧动画. 什么是帧动画? 帧动画,非常好理解.就是轮播,比如我们看电视,其实就是一张一张播放过去的. 正文 <?xml version="1.0" encodi ...

  3. Android 动画具体解释View动画

    为了让用户更舒适的在某些情况下,利用动画是那么非常有必要的.Android在3.0一旦支持两种动画Tween动漫Frame动画.Tween动画支持简单的平移,缩放,旋转,渐变.Frame动画就像Gif ...

  4. iOS 动画基础-显式动画

    摘要 显式动画 属性动画 CABasicAnimation *animation = [CABasicAnimation animation];         [self updateHandsAn ...

  5. 虾扯蛋:Android View动画 Animation不完全解析

    本文结合一些周知的概念和源码片段,对View动画的工作原理进行挖掘和分析.以下不是对源码一丝不苟的分析过程,只是以搞清楚Animation的执行过程.如何被周期性调用为目标粗略分析下相关方法的执行细节 ...

  6. Android动画-View动画

    View动画 Android动画分为三类:View动画,帧动画,和属性动画.帧动画也是View动画的一种. View动画的作用对象是View,之所以强调这一点是因为其作用对象有别于Android的另一 ...

  7. View 动画 Animation 运行原理解析

    这次想来梳理一下 View 动画也就是补间动画(ScaleAnimation, AlphaAnimation, TranslationAnimation...)这些动画运行的流程解析.内容并不会去分析 ...

  8. Android 动画效果 及 自定义动画

    1. View动画-透明动画效果2. View动画-旋转动画效果3. View动画-移动动画效果4. View动画-缩放动画效果5. View动画-动画效果混合6. View动画-动画效果侦听7. 自 ...

  9. Android中的Drawable和动画

    Android中Drawable是一种可以在Canvas上进行绘制抽象的概念,种类很多,常见的颜色和图片都可以是一个Drawable.Drawable有很多种,它们表示一种图像的概念,但是它们又不全是 ...

随机推荐

  1. Spring任务调度实战之Quartz Cron Trigger

    在Quartz中除了使用最简单的Simple Trigger以外,也可以使用类似Linux上Cron作业的CronTrigger的方式来运行Job,下面是一个小例子: 1. 首先是一个任务类,这个类没 ...

  2. python内置函数三

    ord()  函数 和 chr()  相反   chr() 是将数字转换成assci码     ord() 是将字符串转换成assci码 显示 pow() 函数  pow(x,y,z)  表示x**y ...

  3. c基本语法介绍

    c语言基本语法介绍 1.把常量定义为大写字母形式,是一个很好的编程实践.

  4. 阿里云服务器 :Linux环境下搭建Apache+php+mysql

    以前我用的是Windows2012 的服务器,那时候只是抱着玩一玩的心态,所有用的是Windows,但是后来被导师给DISS了,于是决定改服务器的操作系统: (一)下载安装php+mysql+apac ...

  5. 水费管理系统-ER图和流程图

    ER图:

  6. volume 方式使用 Secret【转】

    Pod 可以通过 Volume 或者环境变量的方式使用 Secret,今天先学习 Volume 方式. Pod 的配置文件如下所示: ① 定义 volume foo,来源为 secret mysecr ...

  7. sql 经纬度范围检索(谷歌方案)

    SELECT id, ( * acos ( //公里: 6371 英里: 3959 cos ( radians(78.3232) ) * cos( radians( 数据库纬度字段) ) * cos( ...

  8. R WLS矫正方差非齐《回归分析与线性统计模型》page115

    rm(list = ls()) A = read.csv("data115.csv") fm = lm(y~x1+x2,data = A) coef(fm) A.cooks = c ...

  9. 033、Java中使用简化运算符

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  10. LeetCode160 相交链表(双指针)

    题目: click here!!题目传送门 思路: 1.笨方法 因为如果两个链表相交的话,从相交的地方往后是同一条链表,所以: 分别遍历两个链表,得出两个链表的长度,两个长度做差得到n,然后将长的链表 ...