android 动画分为两类,View Animation(视图动画)和property Animation(属性动画),View Animation(视图动画)包含了Tween Animation和Frame Animation, property Animation包含Value Animation和ObjectAnimation.

  1. View Animation(视图动画)
    1. Tween Animation
    2. Frame Animation
  2. property Animation(属性动画)
    1. Value Animation
    2. ObjectAnimation

Animation类是所有动画(scale,alpha,translate,rotate)的基类,所有派生自Animation的类都具有它的一些公用属性

  1. android:duration : 一次动画的时间
  2. android:fillBefore:动画结束是否恢复到开始前的状态,true 是
  3. android:fillAftre:动画结束是否保持结束时的状态,true 是
  4. android:fillEnable: 同 android:fillBefore
  5. android:repeatCount: 动画执行次数,(在set标签下无效,要设置到具体动画中)
  6. android:repeatMode:动画重复执行的模式:reverse 倒序回放,restart重新播放
  7. android:interpolator: 设置插值器
  8. android:startOffset: 延时多少毫秒开始动画

Tween Animation(补间动画)

  1. alpha   透明度渐变
  2. scale   放缩
  3. translate   移动
  4. rotate   旋转
  5. set   自定义组合动画

动画的调用方式有两种,xml标签实现和代码实现

(一):alpha   透明度渐变

  alpha 动画特有的两个属性:

  1. android:fromAlpha="1"  动画开始时候的透明度,0~1:0表示完全透明,1表示完全不透明
  2. android:toAlpha="0.1"  动画结束时候的透明度

举个栗子:

 <?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1"
android:toAlpha="0.1"
android:duration="2000"
android:repeatCount="5"
android:repeatMode="reverse"
>
</alpha>

(二):scale   放缩渐变

  scale   动画特有的属性:

  1. android:fromXScale="1"  动画开始时,控件在X轴方向上的比例,1表示自身比例,0.5表示自身比例的一半,2表示自身的两倍
  2. android:toXScale="1.4"  动画结束时,控件在X轴方向上的比例,值同上
  3. android:fromYScale="0.4"
  4. android:toYScale="1.4"
  5. android:pivotX="50%"  缩放起始点X轴坐标,值有三种格式,数值,百分比,百分数p,具体含义在注里解释
  6. android:pivotY="50%"  缩放起始点Y轴坐标

注:缩放起始点:默认是控件左上角的点为起始点,  数值 表示 左上角坐标点+这个数值 为起始点,百分比  表示 左上角坐标点+ 自身宽度或高度的值的百分比,百分数p 表示左上角坐标点+这个控件的父控件的宽高乘以这个百分比

举个栗子:

 <?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0.4"
android:toXScale="1.4"
android:fromYScale="0.4"
android:toYScale="1.4"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="3"
android:repeatMode="reverse"
android:duration="3000"
android:fillAfter="true" > </scale>

(二):translate   移动

  translate 动画特有的属性:

  1. android:fromXDelta="0" X轴开始坐标
  2. android:toXDelta="80%p"  X轴结束坐标, 值可以是数值,百分比,百分比p
  3. android:fromYDelta="0"
  4. android;toYDelta="80%"

举个栗子:

 <?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="80%p"
android:fromYDelta="0"
android:toYDelta="80%p"
android:duration="2000"
android:repeatCount="3"
android:repeatMode="reverse"
android:startOffset="1000"
> </translate>

(二):rotate 旋转渐变

  rotate 动画特有的属性:

  1. android:fromDegrees="0" 动画开始旋转的角度,三点钟方向为0°,6点钟方向为90°
  2. android:toDegrees="180" 动画结束旋转的角度
  3. android:pivotX="50%"   旋转的圆心坐标
  4. android:pivotY="50%"  旋转的圆心坐标

举个栗子:

 <?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="180"
android:visible="true"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000"
android:repeatCount="3"
android:repeatMode="reverse"
> </rotate>

(二):set 自定义动画组合

  set 没有自己的特有属性,repeatCount属性不能直接再set标签下设置,设置无效,要设置在里面的具体动画中

举个栗子:

 <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:repeatMode="reverse"
android:fillAfter="true" > <alpha
android:fromAlpha="0.1"
android:toAlpha="1"
android:duration="5000"
android:repeatCount="5"
android:startOffset="1000"
/>
<translate
android:fromXDelta="0"
android:toXDelta="10%"
android:fromYDelta="0"
android:toYDelta="0"
android:repeatCount="3"
android:repeatMode="reverse"/> <rotate
android:fromDegrees="0"
android:toDegrees="180"
android:visible="true"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000"
android:repeatCount="3"
android:repeatMode="reverse"/>
<scale
android:fromXScale="0.4"
android:toXScale="1.4"
android:fromYScale="0.4"
android:toYScale="1.4"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="3"
android:repeatMode="reverse"
android:duration="3000"
android:fillAfter="true"/> </set>

属性介绍完了我们来实现一下:

1.在android studio中创建 xml标签文件

结果:

该文件也可以放在drawable目录下

2.以set举栗子:

  1. 准备xml标签文件set.xml
  2. <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="3000"
    android:fillAfter="true"> <alpha android:fromAlpha="1.0"
    android:toAlpha="0.1"/>
    <scale android:fromXScale="0"
    android:fromYScale="0"
    android:toYScale="1.4"
    android:toXScale="1.4"/>
    <translate android:fromYDelta="0"
    android:fromXDelta="0"
    android:toYDelta="0"
    android:toXDelta="50%"/>
    <rotate android:fromDegrees="0"
    android:toDegrees="90"
    />
    </set>

      

  3. 在布局中放一个TextView
  4. <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.learning.animationapplication.MainActivity"> <TextView
    android:id="@+id/tv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:background="@android:color/holo_blue_bright"/> </android.support.constraint.ConstraintLayout>

      

  5. 在Activity中加载动画

    

package com.learning.animationapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView; public class MainActivity extends AppCompatActivity { private TextView tv;
private Animation animation; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = findViewById(R.id.tv);
animation = AnimationUtils.loadAnimation(this, R.anim.set);//加载动画
tv.startAnimation(animation);//启动动画,并且是立即启动
}
}

  

代码实现,不用xml标签

举例:

 

android---动画入门(一)的更多相关文章

  1. Android动画Animation简单示例

    Animation是Android给我们提供的一个可以实现动画效果的API,利用Animation我们可以实现一系列的动画效果,比如缩放动画,透明度动画,旋转动画,位移动画,布局动画,帧动画等等.An ...

  2. Android面试收集录16 Android动画总结

    一.Android 动画分类 总的来说,Android动画可以分为两类,最初的传统动画和Android3.0 之后出现的属性动画: 传统动画又包括 帧动画(Frame Animation)和补间动画( ...

  3. Android动画效果之自定义ViewGroup添加布局动画

    前言: 前面几篇文章介绍了补间动画.逐帧动画.属性动画,大部分都是针对View来实现的动画,那么该如何为了一个ViewGroup添加动画呢?今天结合自定义ViewGroup来学习一下布局动画.本文将通 ...

  4. Android动画效果之Property Animation进阶(属性动画)

    前言: 前面初步认识了Android的Property Animation(属性动画)Android动画效果之初识Property Animation(属性动画)(三),并且利用属性动画简单了补间动画 ...

  5. Android动画效果之初识Property Animation(属性动画)

    前言: 前面两篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画).Frame Animation(逐帧动画)Andr ...

  6. Android动画效果之Frame Animation(逐帧动画)

    前言: 上一篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画),今天来总结下Android的另外一种动画Frame ...

  7. Android动画效果之Tween Animation(补间动画)

    前言: 最近公司项目下个版本迭代里面设计了很多动画效果,在以往的项目中开发中也会经常用到动画,所以在公司下个版本迭代开始之前,抽空总结一下Android动画.今天主要总结Tween Animation ...

  8. [译]:Xamarin.Android开发入门——Hello,Android Multiscreen深入理解

    原文链接:Hello, Android Multiscreen_DeepDive. 译文链接:Xamarin.Android开发入门--Hello,Android Multiscreen深入理解. 本 ...

  9. [译]:Xamarin.Android开发入门——Hello,Android深入理解

    返回索引目录 原文链接:Hello, Android_DeepDive. 译文链接:Xamarin.Android开发入门--Hello,Android深入理解 本部分介绍利用Xamarin开发And ...

  10. [译]:Xamarin.Android开发入门——Hello,Android快速上手

    返回索引目录 原文链接:Hello, Android_Quickstart. 译文链接:Xamarin.Android开发入门--Hello,Android快速上手 本部分介绍利用Xamarin开发A ...

随机推荐

  1. cw2vec理论及其实现

    导读 本文对AAAI 2018(Association for the Advancement of Artificial Intelligence 2018)高分录用的一篇中文词向量论文(cw2ve ...

  2. AngularJS 最常用的几种功能

    AngularJS 最常用的几种功能 2017-04-13 吐槽阿福 互联网吐槽大会 第一 迭代输出之ng-repeat标签ng-repeat让table ul ol等标签和js里的数组完美结合 1 ...

  3. 6个常见的php安全攻击

    1.SQL注入 SQL注入是一种恶意攻击,用户利用在表单字段输入SQL语句的方式来影响正常的SQL执行.还有一种是通过system()或exec()命令注入的,它具有相同的SQL注入机制,但只针对sh ...

  4. cas 4.1.4单点登录实战

    使用工具 maven-3.3.9 cas-4.1.4 Tomcat-7.0.57-win-x64 cas-sample-Java-webapp 一.Hello cas 1.下载Tomcat,解压:修改 ...

  5. vim折叠快捷键

    参考:http://www.cnblogs.com/fakis/archive/2011/04/14/2016213.html 1. 折叠方式 可用选项来设定折叠方式: 可在Vim 配置文件中设置 s ...

  6. Notify和NotifyAll的区别?

    Notify和NotifyAll都是用来对对象进行状态改变的方式,只是他们的作用域不太一样,从字面上就能看的出来,当对象被上锁之后,当其他的方法要去访问该对象中的数据,就需要该对象对其进行解锁,当然, ...

  7. Intent传值的学习

    今天学习了Intent传值的过程,有点安卓编程经验的都知道,Intent可以实现页面的跳转,可以从一个activity跳转到另一个activity,这个名义上说是界面跳转,其实这句话现在觉得说的很不严 ...

  8. 网络IO和磁盘IO详解

    1. 缓存IO 缓存I/O又被称作标准I/O,大多数文件系统的默认I/O操作都是缓存I/O.在Linux的缓存I/O机制中,数据先从磁盘复制到内核空间的缓冲区,然后从内核空间缓冲区复制到应用程序的地址 ...

  9. 在Workload Automation中实现suspend分析

    1. 背景 这里涉及到两个工具analyze_suspend.py和Workload Automation. 下面analyze_suspend.py简称为ASPY,Workload Automati ...

  10. MySQL中group_concat函数深入理解

    本文通过实例介绍了MySQL中的group_concat函数的使用方法,比如select group_concat(name) . 一.MySQL中group_concat函数 完整的语法如下: gr ...