动画分类:Animation 单一动画

       AnimationSet 复合动画

AnimationSet是Animation的实现子类,Animation是一个抽象类,他的实现子类主要有如下几种:

主要有缩放 ScaleAnimation ,平移TranslateAnimation,透明(不清楚)AlphaAnimation,旋转 RotateAnimation。

Animation作为父类的公用方法:

            SetDuration(..);设置的是动画持续的时间,单位是毫秒:1000=1秒

            SetFillAfter(..);设置动画结束后是否保持状态,false则返回最初状态;

            SetFillBefore(..);

            SetFillEnable(..); //这两个搞不懂

            SetStartOffSet(..);这是动画开始延时时间;

还有几个通用属性:

         pivotXType: 指定x轴中心的类型有三种参数:Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF,Animation.RELATIVE_TO_PARENT

         pivotYtype:指定Y轴中心的类型同x轴

  动画移动选择或者缩放都有一个中心点,这个中心点默认原点是视图左上角的点

  

pivotXTyp的作用就是指定中心点。如果设置成绝对路径Animation.ABSOLUTE,那么就需要计算距离这个原点的距离,把x轴中心设置到x的中间,那么就是view.getWidth()/2

  如果设置成相对自身Animation.RELATIVE_TO_SELF,设置成0.5f就可以了,这个要注意理解。

最后一个是相对父视图的绝对距离这个计算相对麻烦。

以下是主程序:

package com.skymaster.hs.myapplication;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast; public class AnimationTest extends AppCompatActivity {
private ImageView iv_animation;
private Button btn_start1,btn_start2,btn_start3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animation_test);
iv_animation = (ImageView) findViewById(R.id.iv_animation);
btn_start1 = (Button) findViewById(R.id.btn_start1);
btn_start2 = (Button) findViewById(R.id.btn_start2);
btn_start3 = (Button) findViewById(R.id.btn_start3); btn_start1.setOnClickListener(new KeyPress());
btn_start2.setOnClickListener(new KeyPress());
btn_start3.setOnClickListener(new KeyPress());
iv_animation.setOnClickListener(new View.OnClickListener() {
//这里设置ImageView点击监听是为了测试当动画移走之后,点击ImageView
//原来的位置是否有效果,实测是有的,也就是说即使ImageView移走了但是它的
//按键有效位置还是xml布局的那个位置。
@Override
public void onClick(View v) {
Toast.makeText(AnimationTest.this,"ImageClick",Toast.LENGTH_SHORT)
.show();
}
});
} private class KeyPress implements View.OnClickListener{
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btn_start1:
//设定x轴坐标中心点(0,2f),2f是移动自身宽度的两倍
//设定y轴坐标中心点(0,1.5f),同理x轴
TranslateAnimation animation = new TranslateAnimation(Animation.ABSOLUTE,0,Animation.RELATIVE_TO_SELF,2.0f
,Animation.ABSOLUTE,0,Animation.RELATIVE_TO_SELF,1.5f);
animation.setDuration(2000);//持续时间
animation.setStartOffset(1000);
animation.setFillAfter(true);//动画完成保持不会原位
//设定动画监听
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
Toast.makeText(AnimationTest.this,"start!",Toast.LENGTH_SHORT)
.show();
} @Override
public void onAnimationEnd(Animation animation) {
Toast.makeText(AnimationTest.this,"End!",Toast.LENGTH_SHORT)
.show();
} @Override
public void onAnimationRepeat(Animation animation) {
Toast.makeText(AnimationTest.this,"Repeat!",Toast.LENGTH_SHORT)
.show();
}
});
iv_animation.startAnimation(animation);
break;
case R.id.btn_start2:
//设定缩放中心点与缩放比例x轴是0.2f放大到2f,这里都是相对距离
//y轴缩放比例同理,从0.2到3f是放大如果反过来就是缩小
//后面4个参数是设置缩放中心点,用的是绝对距离
ScaleAnimation scaleAnimation = new ScaleAnimation(0.2f,2f,0.2f,3f,Animation.ABSOLUTE
,iv_animation.getWidth()/2,Animation.ABSOLUTE,0);
scaleAnimation.setDuration(2000);
scaleAnimation.setFillAfter(false);
iv_animation.startAnimation(scaleAnimation);
break;
case R.id.btn_start3:
//旋转动画
RotateAnimation rotateAnimation = new RotateAnimation(0f,180f,Animation.RELATIVE_TO_SELF,0.5f,
Animation.RELATIVE_TO_SELF,0.5f);
//rotateAnimation.setFillAfter(true);
rotateAnimation.setFillEnabled(true);
rotateAnimation.setFillBefore(true);
rotateAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
Toast.makeText(AnimationTest.this, "rotateStart!", Toast.LENGTH_SHORT)
.show();
} @Override
public void onAnimationEnd(Animation animation) {
Toast.makeText(AnimationTest.this, "rotateEnd!", Toast.LENGTH_SHORT)
.show();
//iv_animation.startAnimation(animation);
} @Override
public void onAnimationRepeat(Animation animation) {
Toast.makeText(AnimationTest.this, "rotateRepeat!", Toast.LENGTH_SHORT)
.show();
}
});
rotateAnimation.setDuration(2000);
rotateAnimation.setStartOffset(1000);
iv_animation.startAnimation(rotateAnimation);
break;
default:break;
}
}
}
}

xml文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.skymaster.hs.myapplication.AnimationTest"> <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:background="@drawable/ic_launcher"
android:id="@+id/iv_animation"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start1"
android:layout_alignParentBottom="true"
android:id="@+id/btn_start1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start2"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/btn_start1"
android:id="@+id/btn_start2"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start3"
android:layout_toRightOf="@id/btn_start2"
android:layout_alignParentBottom="true"
android:id="@+id/btn_start3"/>
</RelativeLayout>

AnimationSet可以配置多个动画

除了Animation之外还有xml利用多幅图片来实现动画。

利用Animation实现动画,属性并并没有随着动画移动。上面例子中ImageView的点击事件还是在最初的位置,要实现属性动画就要利用ObjectAnimation类

动画Animation的更多相关文章

  1. 动画animation的三个应用(漂浮的白云、旋转的星球、正方体合成)

    × 目录 [1]漂浮的白云 [2]旋转的星球 [3]正方体合成 前面的话 前面介绍过动画animation的详细用法,本文主要介绍动画animation的三个效果 漂浮的白云 [效果演示] [简要介绍 ...

  2. CSS3的变形transform、过渡transition、动画animation学习

    学习CSS3动画animation得先了解一些关于变形transform.过渡transition的知识 这些新属性大多在新版浏览器得到了支持,有些需要添加浏览器前缀(-webkit-.-moz-.- ...

  3. 精灵动画Animation对话框组成Idle动画的各精灵

    精灵动画Animation对话框组成Idle动画的各精灵 1.3  精灵动画 场景中已经添加了精灵,现在是时候让让它动起来了.读者也许已经从精灵图集中,各精灵的命名中看出来了,这个精灵一共有两种动画状 ...

  4. Qt-4.6动画Animation快速入门三字决

    Qt-4.6动画Animation快速入门三字决 Qt-4.6新增了Animation Framework(动画框架),让我们能够方便的写一些生动的程序.不必像以前的版本一样,所有的控件都枯燥的呆在伟 ...

  5. css3 动画(animation)-简单入门

    css3之动画(animation) css3中我们可以使用动画,由于取代以前的gif图片,flash动画,以及部分javascript代码(相信有很多同学都用过jquery中的animate方法来做 ...

  6. Android 动画animation 深入分析

    转载请注明出处:http://blog.csdn.net/farmer_cc/article/details/18259117 Android 动画animation 深入分析 前言:本文试图通过分析 ...

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

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

  8. CSS3动画属性:动画(animation)

    一:动画(animation)的参数详解 由于上面用到了animation动画,这里详细介绍下这个animation的参数. 简介 CSS动画(Animations)简单说就是在一段固定的动画时间内暗 ...

  9. 《The Cg Tutorial》阅读笔记——动画 Animation

    这段时间阅读了英文版的NVidia官方的<The Cg Tutorial>,借此来学习基本的图形学知识和着色器编程. 在此做一个阅读笔记. 本文为大便一箩筐的原创内容,转载请注明出处,谢谢 ...

  10. amazeui学习笔记--css(常用组件15)--CSS动画Animation

    amazeui学习笔记--css(常用组件15)--CSS动画Animation 一.总结 1.css3动画封装:CSS3 动画封装,浏览器需支持 CSS3 动画. Class 描述 .am-anim ...

随机推荐

  1. python 中time.sleep没有作用

    很简单的一个程序: # -*- coding: utf-8 -*- import MySQLdb,os,json,time #from wsgiref.simple_server import mak ...

  2. Java中通过JDBC远程连接Oracle数据库

    通过jdbc连接数据库,拢共分三步: 第一步:下载一个JDBC的驱动,然后把jar包扔到项目里并add to build path: 第二步:去本地oracle文件夹下找到“TNSNAMES.ORA” ...

  3. 2017年1月7日 星期六 --出埃及记 Exodus 21:33

    2017年1月7日 星期六 --出埃及记 Exodus 21:33 "If a man uncovers a pit or digs one and fails to cover it an ...

  4. shell脚本之间互相调用

    在Shell中要如何调用别的shell脚本,或别的脚本中的变量,函数呢? 方法一: . ./subscript.sh 方法二: source ./subscript.sh 注意: .两个点之间,有空格 ...

  5. flume ng之TailSource

    在它里面自带了一个TailSource以及TailDirSource,这个Source是负责读取一个文件,并一行一行的发送到sink端,而在flume-ng 1.4.0里面没有自带TailSource ...

  6. SpringMVC拦截器2(资源和权限管理)(作为补充说明)

    SpringMVC拦截器(资源和权限管理) 1.DispatcherServlet SpringMVC具有统一的入口DispatcherServlet,所有的请求都通过DispatcherServle ...

  7. SqlSever基础 有over函数时,用as为新列起名

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...

  8. 2016ACM/ICPC亚洲区大连站-重现赛

    题目链接:http://acm.hdu.edu.cn/search.php?field=problem&key=2016ACM%2FICPC%D1%C7%D6%DE%C7%F8%B4%F3%C ...

  9. C语言程序设计现代方法_基本类型(第七章)

    C语言支持两种不同的数值类型,整数类型,浮点类型. C语言的整数类型有不同的尺寸.int类型通常为32位,但在老的CPU上可能是16位.有些可能是64位. 因此,int型如果在16位CPU上最大值就是 ...

  10. FZU 2214 Knapsack problem(背包问题)

    Description 题目描述 Given a set of n items, each with a weight w[i] and a value v[i], determine a way t ...