android把动画的模式分为:property animation,view animation,drawable animation.

view animation:给出动画的起止状态,并且通过一定的方式来是view动起来。这个动画只能用于view。

帧动画:是给出一组图片,有drawable来展示动画变化过程。

1.tweened animation

layout:

<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=".AnimationActivity" ><ImageViewandroid:id="@+id/animation_img"android:layout_width="150dp"android:layout_height="150dp"android:layout_centerInParent="true"android:src="@drawable/icon_follower" /><LinearLayoutandroid:id="@+id/action_items"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:orientation="horizontal" ><Buttonandroid:id="@+id/btn_alphaanimation"android:layout_width="wrap_content"android:layout_height="wrap_content"android:singleLine="true"android:text="@string/alpha_animation" /><Buttonandroid:id="@+id/btn_rotateanimation"android:layout_width="wrap_content"android:layout_height="wrap_content"android:singleLine="true"android:text="@string/rotate_animation" /><Buttonandroid:id="@+id/btn_scaleanimation"android:layout_width="wrap_content"android:layout_height="wrap_content"android:singleLine="true"android:text="@string/scale_animation" /><Buttonandroid:id="@+id/btn_translationanimation"android:layout_width="wrap_content"android:layout_height="wrap_content"android:singleLine="true"android:text="@string/scale_animation" /></LinearLayout></RelativeLayout>

activity:

package com.joyfulmath.animatatorsamples;import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.BounceInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.OvershootInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;public class AnimationActivity extends Activity implements OnClickListener{private static final String TAG = "animatatorsamples";Button mAlphaAnimation = null;Button mRotateAnimation = null;Button mScaleAnimation = null;Button mTranslationAnimation = null;ImageView mImage = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_animation_main);mAlphaAnimation = (Button) this.findViewById(R.id.btn_alphaanimation);mAlphaAnimation.setOnClickListener(this);mRotateAnimation = (Button) this.findViewById(R.id.btn_rotateanimation);mRotateAnimation.setOnClickListener(this);mScaleAnimation = (Button) this.findViewById(R.id.btn_scaleanimation);mScaleAnimation.setOnClickListener(this);mTranslationAnimation = (Button) this.findViewById(R.id.btn_translationanimation);mTranslationAnimation.setOnClickListener(this);mImage = (ImageView) this.findViewById(R.id.animation_img);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.animation, menu);return true;}@Overridepublic void onClick(View v) {// TODO Auto-generated method stubswitch(v.getId()){case R.id.btn_alphaanimation:startAlphaAnimation();break;case R.id.btn_rotateanimation:startRotateAnimation();break;case R.id.btn_scaleanimation:startScaleAnimation();break;case R.id.btn_translationanimation:startThanslationAnimation();    break;}}private void startRotateAnimation() {Log.i(TAG, "[startRotateAnimation]");//Animation.RELATIVE_TO_SELF the center of rotateAnimation rotateaAni = new RotateAnimation(0f, 360f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);rotateaAni.setDuration(3000);rotateaAni.setFillAfter(true);rotateaAni.setInterpolator(new LinearInterpolator());        mImage.startAnimation(rotateaAni);}private void startAlphaAnimation() {Log.i(TAG, "[startAlphaAnimation]");AlphaAnimation alphaAni = new AlphaAnimation(1.0f, 0.5f);alphaAni.setDuration(3000);alphaAni.setFillAfter(true);alphaAni.setInterpolator(new OvershootInterpolator());alphaAni.setAnimationListener(new AnimationListener() {@Overridepublic void onAnimationStart(Animation arg0) {// TODO Auto-generated method stubLog.i(TAG, "[onAnimationStart]");}@Overridepublic void onAnimationRepeat(Animation arg0) {// TODO Auto-generated method stubLog.i(TAG, "[onAnimationRepeat]");}@Overridepublic void onAnimationEnd(Animation arg0) {// TODO Auto-generated method stubLog.i(TAG, "[onAnimationEnd]");}});mImage.startAnimation(alphaAni);}private void startScaleAnimation(){float fromX; //1.0f to 0.0ffloat toX; float fromY; float toY;int pivotXType; //where is the last place after scalefloat pivotXValue;int pivotYType; float pivotYValue;    //Animation.ABSOLUTE,         //the last place with X ordinate with absolute diff 20f//Animation.RELATIVE_TO_SELF,   //specified dimension to self//Animation.RELATIVE_TO_PARENT.    //specified dimension to parent move 100%=1f with diff (%parent diff)ScaleAnimation scaleAnim = new ScaleAnimation(1.0f, 0.5f, 1.0f, 0.5f
//                ,Animation.ABSOLUTE, 20f, Animation.RELATIVE_TO_PARENT,
//                2f
                );//ScaleAnimation(float fromX, float toX, float fromY, float toY) 绫讳技Animation.ABSOLUTE,涓攛,y =0;scaleAnim.setDuration(3000);scaleAnim.setFillAfter(true);scaleAnim.setInterpolator(new OvershootInterpolator());mImage.startAnimation(scaleAnim);}private void startThanslationAnimation(){Log.i(TAG, "[startThanslationAnimation]");//Animation.ABSOLUTE where is the last point show place//the start x,y ordinate is the current place with translation TranslateAnimation anmit= new TranslateAnimation(Animation.RELATIVE_TO_PARENT,0.1f,Animation.RELATIVE_TO_PARENT,0.5f,Animation.RELATIVE_TO_PARENT,0.2f,Animation.RELATIVE_TO_PARENT, 0.6f);anmit.setDuration(3000);anmit.setFillAfter(true);anmit.setInterpolator(new BounceInterpolator());mImage.startAnimation(anmit);    }}

animation 是一种变换动画,也就是实际的响应位置和大小并没有变化,只是视图上的变换。

这种动画变换成本低,效率高。

这些类都继承自android.view.animation.Animation

2.animationset

view视图动画组合只用是一个view对象的多种状态变换。

    /*** Constructor to use when building an AnimationSet from code* * @param shareInterpolator Pass true if all of the animations in this set*        should use the interpolator associated with this AnimationSet.*        Pass false if each animation should use its own interpolator.*/public AnimationSet(boolean shareInterpolator) {setFlag(PROPERTY_SHARE_INTERPOLATOR_MASK, shareInterpolator);init();}

如androidsdk源码所示,shareInterpolator将决定使用每个animation的interpolator

还是animationset的变换方式。

animationset的变换只能一起播放,只有通过startoffset的方式可以模拟变换的顺序。

3.android.view.animation.BaseInterpolator

变换方式:

末前支持的是:

AccelerateDecelerateInterpolator,  开始和结束变换慢,中间变换快速

AccelerateInterpolator,          开始缓慢,然后加速

AnticipateInterpolator,        变换会有一个回调,也就是先向后变换,然后按照给定关键帧的方式变换。   

AnticipateOvershootInterpolator,      An interpolator where the change starts backward then flings forward and overshoots the target value and finally goes back to the final value

BounceInterpolator,         贝叶斯曲线

CycleInterpolator,          sin曲线

DecelerateInterpolator,        减速变化

LinearInterpolator,          默认,线性变换

OvershootInterpolator,        An interpolator where the change flings forward and overshoots the last value then comes back.

PathInterpolator          5.1新功能。可以自定义变换路径方式。         

转载于:https://www.cnblogs.com/deman/p/4357455.html

animation of android (1)相关推荐

  1. [Android]使用Kotlin开发Android(二)

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/4829007.html [TOC] 使用Kotlin+OkHtt ...

  2. Android(Xamarin)之旅(三)

    Android(Xamarin)之旅(三) 原文:Android(Xamarin)之旅(三) 前面两篇说到了Xamarin的安装和一些简单的控件,今天来说说一些对话框和提示信息,以及简单的布局元素. ...

  3. WPF使用Animation仿WeChat(微信)播放语音消息

    WPF开发者QQ群: 340500857 前言 WPF使用Animation仿WeChat(微信)播放语音消息? 效果图: 创建MyAnimationForever.cs如下: public clas ...

  4. Gradle For Android(三)Gradle优化与灵活的使用技巧

    <Gradle For Android(三)Gradle优化与灵活的使用技巧 > 转载请注明来自傻小孩b(gold.xitu.io/user/57e089-喜欢的可以关注我,不定期总结文章 ...

  5. Android(安卓)订餐APP(Sqlite数据库,完整的增删改查)

     Android(安卓)订餐APP(Sqlite数据库,完整的增删改查) 一.背景 首先说说项目的背景,基于地铁口鸡蛋饼的一个小项目,APP中固定设置的鸡蛋饼搭配,顾客也可以自己搭配 二.开发环境 A ...

  6. Android(一)win10配置java环境、安装Android studio

    Android(一)win10配置java环境.安装Android studio 从这篇文章开始,我将记录从配置环境到完成Android开发基础知识学习的过程.在学习过程中,参考的有郭霖大神的< ...

  7. 处女男学Android(十一)---Gallery、ViewPager和ViewPager+Fragment实现的Tab导航

    一.前言 转载请标明出处:http://blog.csdn.net/wlwlwlwl015/article/details/42087915 有阵子没更新博客了,主要是最近公司接了个P2P的金融借贷项 ...

  8. 深入理解Android(一):Gradle详解

    http://www.infoq.com/cn/articles/android-in-depth-gradle/ http://www.infoq.com/cn/articles/android-i ...

  9. 「WGCLOUD」支持监测Android(安卓)终端手机的状态吗

    支持的 android(安卓)设备监测使用说明(需要升级到WGCLOUD v3.3.8或以上版本) 1.首先需要在android(安卓)设备开启如下两项: a.启用开发者选项(一般在安卓设备版本号处, ...

最新文章

  1. 算法------零钱兑换(Java版本)
  2. 词袋模型BoW图像检索Python实战
  3. Python继承外另一种重用方式——组合
  4. DOS网络命令之 tracert
  5. leetcode - 873. 最长的斐波那契子序列的长度(使用到哈希表)
  6. 导航菜单UI设计中的作用,优秀案例临摹起来!
  7. ARMv8体系结构基础05:比较和跳转指令
  8. 全国2013年最新电子地图矢量数据超图格SGD、MAPINFO、GST、SMW、SHP格式等
  9. hdmi接口和计算机连接,hdmi接口,手把手教你hdmi接口怎么连接电视
  10. Thymeleaf模板引擎使用详解
  11. 卫星星座 - 2021 年行业调查和趋势 Satellite Constellations - 2021 Industry Survey and Trends阅读报告
  12. html动画引擎,AlloyStic HTML5骨骼动画
  13. Mac系统中键盘失灵后的解决小技巧
  14. EXCEL 自动求和
  15. Tangent Element调色台的设计和功能同等重要
  16. 六脉连环大总结,教你干趴Docker
  17. python表示差值_python差值函数
  18. Let‘s Go Rust 系列之定时器 Ticker Timer
  19. 笔记本加装SSD重装系统win10引导始终指向原系统的问题终极解决方法
  20. c语言中常用数学符号,C语言中常用的数学公式

热门文章

  1. 程序员最担心,在乎的几个问题!论12年的职业生涯,能给我带来什么!
  2. WEB入门实践-张晨光-专题视频课程
  3. 《剑指offer》求二叉树的最小深度(非递归法)
  4. 爬虫基于ADSL动态获取ip
  5. rJava安装及Java 开发R
  6. Elasticsearch如何关掉服务
  7. 如何成为阿里巴巴大数据开发工程师?你要学习很多东西
  8. JavaScript实现按键精灵
  9. java使用Crawler4j开发爬虫
  10. 算法笔记(JavaScript版)——排序