Android动画分为Tween动画和Frame动画,近期学习了,体tween动画,现在讲学习的心得以及相关知识介绍如下。

Tween又称为补间动画,可以把对象进行缩小、放大、旋转和渐变等操作。

   第一: Tween动画四个主要实现类:
1、AlphaAnimation:渐变(颜色)动画,主要控制透明度变化动画类,常使用AlphaAnimation(float fromAlpha, float toAlpha)来构造;
    fromAlpha:动画开始时的透明度(取值范围为0.0到1.0);
    toAlpha:动画结束时的透明度;
2、ScaleAnimation:主要控制大小变化,常使用ScaleAnimation(float fromX, float toX, float fromY, float toY, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)来构造;
    fromX:动画开始X坐标上的伸缩尺度(是相对于原来图片的大小而言);
    toX:动画结束X坐标上的伸缩尺度;
    fromY:动画开始Y坐标上的伸缩尺度;
    toY:动画结束Y坐标上的伸缩尺度;
    pivotXType:X坐标上的伸缩模式(类型),取值有:Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF:相对于自身, Animation.RELATIVE_TO_PARENT;
    pivotXValue:X坐标上缩放的中心位置;
    pivotYType:Y坐标上的伸缩模式,取值有:Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_PARENT;
    pivotYValue:Y坐标上缩放的中心位置;
3、TranslateAnimation:主要控制位置变换的动画实现类,常使用TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)来构造;
    fromXDelta:动画开始的X坐标;
    toXDelta:动画结束的X坐标;
    fromYDelta:动画开始的Y坐标;
    toYDelta:动画结束的Y坐标;
4、RotateAnimation:主要控制旋转的动画实现类,常使用RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)来构造;
    fromDegrees:旋转开始角度;
    toDegrees:旋转结束角度;
    pivotXType, pivotXValue, pivotYType, pivotYValue与尺度变化动画ScaleAnimation类似;
 
第二:所包含的共用的方法
 
//设置播放时间
animation.setDuration(2000); //设置重复的次数,记着是重复的次数 animation.setRepeatCount(2); //设置重复的模式,有两种RESTART:重新开始与REVERSE:反向开始 animation.setRepeatMode(AlphaAnimation.REVERSE); //启动播放 iv.startAnimation(animation);

第三:实例,

布局文件我们这样写,

<LinearLayout 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:orientation="vertical"

    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.ftf.tween.MainActivity" >

    <LinearLayout

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:orientation="horizontal" >

        <Button

            android:onClick="click"

            android:text="透明度"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:orientation="horizontal" />

        <Button

            android:onClick="click2"

            android:text="缩放"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:orientation="horizontal" />

        <Button

            android:onClick="click3"

            android:text="旋转"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:orientation="horizontal" />

        <Button

            android:onClick="click4"

            android:text="平移"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:orientation="horizontal" />

        <Button

            android:onClick="click5"

            android:text="组合"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:orientation="horizontal" />

    </LinearLayout>

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:gravity="center" >

        <ImageView

            android:id="@+id/iv"

            android:src="@drawable/ic_launcher"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

             />

    </LinearLayout>

</LinearLayout>
activity中,这样写:
 

// 透明度变化

public void click(View view) {

AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);

animation.setDuration(2000);

animation.setRepeatCount(2);

animation.setRepeatMode(AlphaAnimation.REVERSE);

iv.startAnimation(animation);

}

public void click2(View view) {

ScaleAnimation animation = new ScaleAnimation(0.2f, 2.0f, 0.2f, 2.0f,

Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,

0.5f);

animation.setDuration(2000);

animation.setRepeatCount(2);

animation.setRepeatMode(AlphaAnimation.REVERSE);

iv.startAnimation(animation);

}

public void click3(View view) {

RotateAnimation animation = new RotateAnimation(0, 360,

Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,

0.5f);

animation.setDuration(2000);

animation.setRepeatCount(2);

animation.setRepeatMode(AlphaAnimation.REVERSE);

iv.startAnimation(animation);

}

public void click4(View view) {

TranslateAnimation animation = new TranslateAnimation(

Animation.RELATIVE_TO_PARENT, 0.2f,

Animation.RELATIVE_TO_PARENT, 1.0f,

Animation.RELATIVE_TO_PARENT, 0.2f,

Animation.RELATIVE_TO_PARENT, 1.0f);

animation.setDuration(2000);

animation.setRepeatCount(2);

animation.setRepeatMode(AlphaAnimation.REVERSE);

iv.startAnimation(animation);

}

public void click5(View view) {

//设置混合模式,也即多重播放效果放在一起。

AnimationSet set = new AnimationSet(false);

TranslateAnimation pa = new TranslateAnimation(

Animation.RELATIVE_TO_PARENT, 0.2f,

Animation.RELATIVE_TO_PARENT, 1.0f,

Animation.RELATIVE_TO_PARENT, 0.2f,

Animation.RELATIVE_TO_PARENT, 1.0f);

pa.setDuration(2000);

pa.setRepeatCount(2);

pa.setRepeatMode(AlphaAnimation.REVERSE);

RotateAnimation ra = new RotateAnimation(0, 360,

Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,

0.5f);

ra.setDuration(2000);

ra.setRepeatCount(2);

ra.setRepeatMode(AlphaAnimation.REVERSE);

ScaleAnimation sa = new ScaleAnimation(0.2f, 2.0f, 0.2f, 2.0f,

Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,

0.5f);

sa.setDuration(2000);

sa.setRepeatCount(2);

sa.setRepeatMode(AlphaAnimation.REVERSE);

set.addAnimation(sa);

set.addAnimation(ra);

set.addAnimation(pa);

iv.startAnimation(set);

}
 

Android学习笔记-tween动画之java实现的更多相关文章

  1. Android学习笔记-tween动画之xml实现

    继上篇tween动画的java实现:http://www.cnblogs.com/fengtengfei/p/3957800.html, 这里我接着介绍一下tween动画的xml实现的方法,   首先 ...

  2. Android学习笔记_55_Tween动画 (渐变、缩放、位移、旋转)

    Android 平台提供了两类动画. 一类是Tween动画,就是对场景里的对象不断的进行图像变化来产生动画效果(旋转.平移.放缩和渐变).第二类就是 Frame动画,即顺序的播放事先做好的图像,与gi ...

  3. Android学习笔记_39_tween动画的实现(Animation和Frame)

    一.Animation动画的实现及特点: 1.Tween动画,通过对 View 的内容进行一系列的图形变换 (包括平移.缩放.旋转.改变透明度)来实现动画效果.   动画效果的定义可以采用XML来做也 ...

  4. Android学习笔记02-Mac下编译java代码

    在Mac OS上配置JDK 1.7. 一 下载 Mac版本的JDK1.7 从以下下载地址,下载Mac版本的JDk1.7 安装文件 jdk-7u79-macosx-x64.dmg. http://www ...

  5. Android学习笔记01-Mac下搭建Java开发环境

    一 安装JDK 下载 mac 下专用的jdk1.7, 下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downlo ...

  6. Android学习笔记(四) JAVA基础知识回顾

    一.接口 1)接口中定义的方法都是public权限,并且默认为public,而不是default. 2)接口的实现(implements)是特殊的继承,类似于父类子类的关系,可以向上转型(非常重要). ...

  7. Android 学习笔记之Volley(七)实现Json数据加载和解析...

    学习内容: 1.使用Volley实现异步加载Json数据...   Volley的第二大请求就是通过发送请求异步实现Json数据信息的加载,加载Json数据有两种方式,一种是通过获取Json对象,然后 ...

  8. Android学习笔记进阶之在图片上涂鸦(能清屏)

    Android学习笔记进阶之在图片上涂鸦(能清屏) 2013-11-19 10:52 117人阅读 评论(0) 收藏 举报 HandWritingActivity.java package xiaos ...

  9. Android学习笔记之JSON数据解析

    转载:Android学习笔记44:JSON数据解析 JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,为Web应用开发提供了一种 ...

随机推荐

  1. jquery ajax 同步异步的执行

    jquery ajax 同步异步的执行   大家先看一段简单的jquery ajax 返回值的js 代码 function getReturnAjax{  $.ajax({    type:" ...

  2. react-native 0.58版本打包图片问题 task ':app:mergeReleaseResources' Error: Duplicate resources

    debug没问题,在生成正式apk的时候就如下: google了一下在github上找到了解决方案: github问题指向 在node_modules/react-native/react.gradl ...

  3. HDU - 2612 Find a way(BFS搜索)

    题目: 链接 思路: 用BFS分别以‘Y’和‘M’的位置为起点进行两次搜索,并把这两次的搜索结果在一个二维数组中保存下来,在对地图遍历遇到‘@’更行最小值. PS: 如果用‘Y’和‘M’点分别去搜每个 ...

  4. Java中Date类型的工具类

    package com.mytripod.util; import java.text.DateFormat; import java.text.SimpleDateFormat; import ja ...

  5. 零基础入门学习Python(14)--字符串:各种奇葩的内置方法

    前言 这节课我们回过头来,再谈一下字符串,或许我们现在再来谈字符串,有些朋友可能觉得没必要了,甚至有些朋友就会觉得,不就是字符串吗,哥闭着眼也能写出来,那其实关于字符串还有很多你不知道的秘密哦.由于字 ...

  6. 201621123079《Java程序设计》第1周学习总结

    第1周-Java基本概念 1.本周学习总结 第一次上课接触java,了解了java的由来和历史,还有JCP,JSP的概念,并学会如何建立一个java文件和运行过程.感觉java比之前学习的数据结构更高 ...

  7. c++基础_时间转换

    #include <iostream> using namespace std; int main(){ int n; cin>>n; ,b=,c=; )!=){ a=n/; ...

  8. python+selenium之元素的八大定位方法

    以百度搜索框为例,先打开百度网页 1.点右上角爬虫按钮 2.点左下角箭头 3.讲箭头移动到百度搜索输入框上,输入框高亮状态 4.下方红色区域就是单位到输入框的属性: <input id=&quo ...

  9. JQuery常用的案例

    1.给导航栏添加鼠标移上去的时候变换背景颜色的方法. $(function () { $(".nav li").mouseover(function () { $(this).cs ...

  10. 易接SDK ios9以上无法弹出充值界面的一种情况

    充值需要用到http请求: 打开info.plist, 在app tansport security  setting 这个项 ,  加入  NSAllowsArbitraryLoads YES