先上效果图:

我这里用的是GifCam来制作的gif动画,能够在http://download.csdn.net/detail/baidu_nod/7628461下载,

制作过程是先起一个模拟器,然后把GifCam的框拖到模拟器上面。点击Rec的new先,然后点击Rec,然后就save到本地成gif文件

这里做一个左右旋转。上下旋转,和左右移动的动画。先自己建立一个View的类,作为操作的对象:

public class MyView extends View {

	private Paint mPaint;
int width = 0;
int height = 0; public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
mPaint = new Paint();
mPaint.setStrokeWidth(5);
mPaint.setColor(Color.RED);
this.setBackgroundColor(Color.RED);
width = context.getResources().getDimensionPixelSize(R.dimen.width);
height = context.getResources().getDimensionPixelSize(R.dimen.height); } @Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//width 300 height 300
canvas.drawLine(0, 0, width, 0, mPaint);
canvas.drawLine(width, 0, width, height, mPaint);
canvas.drawLine(width, height, 0, height, mPaint);
canvas.drawLine(0, height, 0, 0, mPaint);
canvas.save();
} }

左右旋转动画:

public class RotateLeftRightAnimation extends Animation {
private final float mFromDegrees;
private final float mToDegrees;
private final float mCenterX;
private final float mCenterY;
private final float mDepthZ;
private final boolean mReverse;
private Camera mCamera; private InterpolatedTimeListener listener; public RotateLeftRightAnimation(float fromDegrees, float toDegrees, float centerX, float centerY, float depthZ,
boolean reverse) {
mFromDegrees = fromDegrees;
mToDegrees = toDegrees;
mCenterX = centerX;
mCenterY = centerY;
mDepthZ = depthZ;
mReverse = reverse;
} public static interface InterpolatedTimeListener {
public void interpolatedTime(float interpolatedTime);
} public void setInterpolatedTimeListener(InterpolatedTimeListener listener) {
this.listener = listener;
} @Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
mCamera = new Camera();
} @Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
if (listener != null) {
listener.interpolatedTime(interpolatedTime);
}
final float fromDegrees = mFromDegrees;
float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime); boolean overHalf = (interpolatedTime > 0.5f);
if (overHalf) {
degrees = degrees - 180;
} final float centerX = mCenterX;
final float centerY = mCenterY;
final Camera camera = mCamera;
final Matrix matrix = t.getMatrix();
camera.save();
if (mReverse) {
camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
} else {
camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
}
<span style="color:#ff0000;">camera.rotateY(degrees); //这个Y轴旋转就是左右旋转</span>
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);//这两句的意思是把View移到原点后旋转完再移动到如今的位置
}
}

假设是上线旋转就把camera.rotateY(degrees)改成camera.rotateX(degrees)

假设是移动的话

<span style="color:#330033;">public class MoveAnimation extends Animation {
private Camera mCamera;
private float mMoveDistance; private InterpolatedTimeListener listener; public MoveAnimation(float moveDistance) {
mMoveDistance = moveDistance;
} public static interface InterpolatedTimeListener {
public void interpolatedTime(float interpolatedTime);
} public void setInterpolatedTimeListener(InterpolatedTimeListener listener) {
this.listener = listener;
} @Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
mCamera = new Camera();
} @Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
if (listener != null) {
listener.interpolatedTime(interpolatedTime);
} final Camera camera = mCamera;
final Matrix matrix = t.getMatrix();
camera.save(); camera.getMatrix(matrix);
camera.restore();
matrix.postTranslate(mMoveDistance, 0);
}
}</span>

然后主程序这样来调用:

	final MyView myView = (MyView) findViewById(R.id.myview);

		Button btn = (Button) findViewById(R.id.btn_move);
btn.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
MoveAnimation anim = new MoveAnimation(200);
anim.setDuration(500);
myView.startAnimation(anim);
}
}); Button btn_up_down_rotate = (Button) findViewById(R.id.btn_up_down_rotate);
btn_up_down_rotate.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
RotateUpDownAnimation anim = new RotateUpDownAnimation(0,
180, v.getWidth() / 2, v.getHeight() / 2, 0, false);
anim.setDuration(500);
myView.startAnimation(anim);
}
}); Button btn_left_right_rotate = (Button) findViewById(R.id.btn_left_right_rotate);
btn_left_right_rotate.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
RotateLeftRightAnimation anim = new RotateLeftRightAnimation(0,
180, v.getWidth() / 2, v.getHeight() / 2, 0, false);
anim.setDuration(500);
myView.startAnimation(anim);
}
});

android旋转动画和平移动画具体解释,补充说一下假设制作gif动画放到csdn博客上的更多相关文章

  1. 【转】Android Building System 总结 - 一醉千年 - CSDN博客

    原文网址:http://www.360doc.com/content/15/0314/23/1709014_455175716.shtml  Android Building System 总结 收藏 ...

  2. Android应用开发-小巫CSDN博客client之获取评论列表

    Android应用开发-小巫CSDN博客客户端之获取评论列表 上一篇博客介绍了博文具体内容的业务逻辑实现,本篇博客介绍小巫CSDN博客客户端的最后一项功能.获取评论列表,这个功能的实现跟前面获取文章列 ...

  3. Android应用开发-小巫CSDN博客client之嵌入有米广告

    Android应用开发-小巫CSDN博客client之嵌入有米广告 上一篇博客给大家介绍怎样集成友盟社会化组件,本篇继续带来干货,教大家怎样嵌入广告到应用中去.小巫自称专业对接30年,熟悉各大渠道SD ...

  4. Android应用开发-小巫CSDN博客clientJsoup篇

    Android应用开发-小巫CSDN博客clientJsoup篇 距上一篇博客已经过去了两个星期,小巫也认为很抱歉,由于在忙着做另外一个项目,差点儿抽不出空来,这不小巫会把剩下的博文全部在国庆补上.本 ...

  5. Android应用开发-小巫CSDN博客client之显示博文具体内容

    Android应用开发-小巫CSDN博客客户端之显示博文具体内容 上篇博文给大家介绍的是怎样嵌入有米广告而且获取收益,本篇博客打算讲讲关于怎样在一个ListView里显示博文的具体信息.这个可能是童鞋 ...

  6. 基于Netbeans的安卓Android开发环境配置 - CSDN博客

    原文:基于Netbeans的安卓Android开发环境配置 - CSDN博客 基于Netbeans的安卓Android开发环境配置 一.准备工作 NetBeans 勾选网页中的Accept-选择对应系 ...

  7. 修复在“Android 在ScrollView中嵌入ViewPage后ViewPage不能很好的工作的问题解决”这篇博客中MyScrollView出现滑动一会就不会上下滑动的问题

    在“Android 在ScrollView中嵌入ViewPage后ViewPage不能很好的工作的问题解决”,这篇博客中的大部分问题已经解决了. 唯一遗憾的是,ViewPage随人能够工作了,但是My ...

  8. android开源应用(主要是博客上带有分析的)收集 【持续更新】

    2014.5.24更新: (android高仿系列)今日头条    http://blog.csdn.net/vipzjyno1/article/details/26514543 CSDN Andro ...

  9. android中MVP模式(一) - 清风明月的专栏 - CSDN博客

    presenter 主持人.主导器 ====== 1. 明确需求,界面如下:可存,可根据id读取数据. 包结构图 2. 建立bean public class UserBean { private S ...

随机推荐

  1. 浅谈C#中的泛型

    1.什么是泛型? 泛型是程序设计语言的一种特性.允许程序员在强类型程序设计语言中编写 代码时定义一些可变部分,那些部分在使用前必须作出指明.各种程序设计语言和其编译器.运行环境对泛型的支持均不一样.将 ...

  2. AJAX - 类型“System.Web.UI.UpdatePanel”不具有名为“FileUpload”的公共属性。

    类型“system.web.ui.updatepanel” 不具有名为“***”的公共属性,其实原因很简单.就是少了一个<ContentTemplate></ContentTempl ...

  3. ABAP 向上取整和向下取整 CEIL & FLOOR

    下面是一段关于CEIL 和 FLOOR 的代码 DATA:a TYPE mseg-menge, b TYPE mseg-menge, c TYPE mseg-menge. a = '1.36'. b ...

  4. Swift - 使用NSURL进行数据的提交和获取(POST与GET)

    使用Swift进行iOS开发时,不可避免的要进行远程的数据获取和提交. 其数据请求的方式既可能是POST也可能是GET.同不管是POST还是GET又可以分为同步请求和异步请求. 下面通过四个例子来进行 ...

  5. IE浏览器上传文件时本地路径变成”C:\fakepath\”的问题

    在使用<input id="file_upl" type="file" />控件上传文件时,有时会需要获取文件本地路径展示给客户,这时可以通过这样的 ...

  6. matlab画棋盘格程序

    转载请注明出处:zhouyelihua**http://blog.csdn.net/zhouyelihua/article/details/46674191** 意义 在摄像机标定过程中经常须要打印棋 ...

  7. 第四章 Spring与JDBC的整合

    这里选择的是mysql数据库. 4.1引入aop.tx的命名空间 为了事务配置的需要,我们引入aop.tx的命名空间 <?xml version="1.0" encoding ...

  8. VirtualBox集群建立和网络配置

    安装 1. 安装 安装Oracle VM VirtualBox之后,新建一个虚拟机,制定好内存等信息,开始安装操作系统,这里安装ubuntu-12.04.2-desktop-i386版本. 2. 拷贝 ...

  9. setenv 和 set

    setenv 和 set 是在csh系列的命令,当然bash中也有set,还是有出入的.   set 是对当前进程有效,不会传递给子进程 setenv 不仅对当前进程有效,也会传递给子进程.   语法 ...

  10. 疯狂Android演讲2 环境配置

    笔者:本笃庆军 原文地址:http://blog.csdn.net/qingdujun/article/details/37053681 jdk-6u3-windows-i586-p.exe  下载地 ...