透明度动画、旋转动画、尺寸伸缩动画、移动动画

package com.javen.tween;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
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 MainActivity extends Activity {
private ImageView image;
private Button but1;
private Button but2;
Bitmap bm; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
but1.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
image.setImageBitmap(rotateToFit(bm, -90f));
bm = rotateToFit(bm, -90f);
}
});
but2.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
image.setImageBitmap(rotateToFit(bm, 90f));
bm = rotateToFit(bm, 90f);
}
}); image.setOnClickListener(new View.OnClickListener() { @TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onClick(View v) {
System.out.println("你点击了图片");
initAnimation();
}
});
} @SuppressLint("NewApi")
private void init() {
image = (ImageView) findViewById(R.id.image);
but1 = (Button) findViewById(R.id.but1);
but2 = (Button) findViewById(R.id.but2);
but1.setText("向左转");
but2.setText("向右转");
bm = BitmapFactory.decodeResource(getResources(), R.drawable.eee);
image.setImageBitmap(bm);
image.setAlpha(alpha);
} public static Bitmap rotateToFit(Bitmap bm, float degrees) {
int wight = bm.getWidth();
int height = bm.getHeight(); Matrix matrix = new Matrix();
matrix.postRotate(degrees);
Bitmap resBitmap = Bitmap.createBitmap(bm, 0, 0, wight, height, matrix,
true);
return resBitmap; }
private Animation animation_alpha,animation_scale,animation_translate,animation_rotate;
private AnimationSet animationSet;
private void initAnimation() {
//透明度控制动画效果 alpha
animation_alpha=new AlphaAnimation(0.1f,1.0f);
//第一个参数fromAlpha为 动画开始时候透明度
//第二个参数toAlpha为 动画结束时候透明度
animation_alpha.setRepeatCount(0);//设置循环
animation_alpha.setDuration(5000);//设置时间持续时间为 5000毫秒 // 旋转效果rotate
animation_rotate = new RotateAnimation(0, -720,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
//第一个参数fromDegrees为动画起始时的旋转角度
//第二个参数toDegrees为动画旋转到的角度
//第三个参数pivotXType为动画在X轴相对于物件位置类型
//第四个参数pivotXValue为动画相对于物件的X坐标的开始位置
//第五个参数pivotXType为动画在Y轴相对于物件位置类型
//第六个参数pivotYValue为动画相对于物件的Y坐标的开始位置
animation_rotate.setRepeatCount(0);
animation_rotate.setDuration(5000);//设置时间持续时间为 5000毫秒 //尺寸伸缩动画效果 scale
animation_scale=new ScaleAnimation(0.1f,3.0f,0.1f,3.0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
//第一个参数fromX为动画起始时 X坐标上的伸缩尺寸
//第二个参数toX为动画结束时 X坐标上的伸缩尺寸
//第三个参数fromY为动画起始时Y坐标上的伸缩尺寸
//第四个参数toY为动画结束时Y坐标上的伸缩尺寸
/*说明:
以上四种属性值
0.0表示收缩到没有
1.0表示正常无伸缩
值小于1.0表示收缩
值大于1.0表示放大
*/
//第五个参数pivotXType为动画在X轴相对于物件位置类型
//第六个参数pivotXValue为动画相对于物件的X坐标的开始位置
//第七个参数pivotXType为动画在Y轴相对于物件位置类型
//第八个参数pivotYValue为动画相对于物件的Y坐标的开始位置
animation_scale.setRepeatCount(0);
animation_scale.setDuration(5000);//设置时间持续时间为 5000毫秒 //移动动画效果translate
animation_translate=new TranslateAnimation(-20f,300f,-20f,300f);
//第一个参数fromXDelta为动画起始时 X坐标上的移动位置
//第二个参数toXDelta为动画结束时 X坐标上的移动位置
//第三个参数fromYDelta为动画起始时Y坐标上的移动位置
//第三个参数toYDelta为动画结束时Y坐标上的移动位置
animation_translate.setRepeatCount(0);//设置动画执行多少次,如果是-1的话就是一直重复
animation_translate.setDuration(5000);//设置时间持续时间为 5000毫秒 animationSet=new AnimationSet(true); animationSet.addAnimation(animation_alpha);//透明度
animationSet.addAnimation(animation_rotate);//旋转
animationSet.addAnimation(animation_scale);//尺寸伸缩
animationSet.addAnimation(animation_translate);//移动
image.startAnimation(animationSet);//开始播放
} }

Android动画Animation之Tween用代码实现动画的更多相关文章

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

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

  2. Android动画学习(二)——Tween Animation

    前两天写过一篇Android动画学习的概述,大致的划分了下Android Animation的主要分类,没有看过的同学请移步:Android动画学习(一)——Android动画系统框架简介.今天接着来 ...

  3. Android 动画——Frame Animation与Tween Animation

    很多手机应用的引导页都是动画的,添加动画后的应用画面会更加生动灵活,今天博主也学习了Android中Animation的使用,下面来总结下.  android中的Animation分为两种,一种是Fr ...

  4. Android Property Animation动画

    3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中又引入了一个新的动画系统:property animation,这三 ...

  5. 【Android动画】之Tween动画 (渐变、缩放、位移、旋转)

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

  6. Android Property Animation 物业动画

    效果图:   Property Animation介绍: 出生在sdk3.0,是利用了View所拥有的属性,进行一系列的操作. 比方一个View有什么样的setAbc的属性,那么理论上就能够设置它. ...

  7. Android动画Animation简单示例

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

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

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

  9. 安卓开发20:动画之Animation 详细使用-主要通过java代码实现动画效果

    AlphaAnimation 透明效果实现: activity_main.xml中仅仅是一个简单的图片,下面的例子都会使用这个xml: <RelativeLayout xmlns:android ...

随机推荐

  1. Android开发之onClick事件的实现

    算是从2015年开始学习android开发,目前把onClick的事件实现写下来,记录下,以备参考. 实现button的点击功能,让textView显示一行文字,最简单的onClick事件. 直接贴代 ...

  2. 配置oschina for pc 开发环境

    oschina for pc 是一款用python + pyqt + html + css +js开发的桌面程序,感觉十分强大.python开发快捷, 网页技术绚丽,正是桌面程序需要的. 感谢铂金小鸟 ...

  3. innodb b+树

    http://www.admin10000.com/document/5372.html

  4. bzoj4511: [Usaco2016 Jan]Subsequences Summing to Sevens

    前缀和. 设f[i]为前缀和%7=i的第一个点.那么答案就是max(i-f[s[i]%7])了. #include<cstdio> #include<algorithm> #i ...

  5. 触摸屏网站开发系列(一)-ios web App应用程序(ios meta)

    触摸屏网站的开发其实现在来讲比前几年移动端网站开发好多了,触摸屏设备IOS.Android.BBOS6等系统自带浏览器均为WEBKIT核心,这就说明PC上面尚未立行的HTML5 CSS3能够运用在这里 ...

  6. 阿里云至 Windows Azure 的 Linux 虚拟机迁移

    在Windows Azure中,用户可以对部署在Azure中的虚拟机的映像.磁盘以及快照进行生成和下载.用户可以方便地将Azure中的虚拟机实例迁移到本地.私有云甚至其他公有云平台进行测试.扩展或者再 ...

  7. Mysql主从复制的实现

    MySQL是一个开放源码的小型关联式数据库管理系统,开发者为瑞典MySQL AB公司.MySQL被广泛地应用在Internet上的中小型网站中.由于其体积小.速度快.总体拥有成本低,尤其是开放源码这一 ...

  8. JDBC基础教程

    本文实例讲述了JDBC基础知识与技巧.分享给大家供大家参考.具体分析如下: 1.什么是JDBC? 通俗来讲JDBC技术就是通过java程序来发送SQL语句到数据库,数据库收到SQL语句后执行,把结果返 ...

  9. POJ 2243 Knight Moves

    Knight Moves Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13222   Accepted: 7418 Des ...

  10. POJ3241 Object Clustering 曼哈顿最小生成树

    题意:转换一下就是求曼哈顿最小生成树的第n-k条边 参考:莫涛大神的论文<平面点曼哈顿最小生成树> /* Problem: 3241 User: 96655 Memory: 920K Ti ...