先上效果图:

我这里用的是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. JQuery - 判断radio是否选中,获取选中值

    代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3. ...

  2. shell telnet 路由器

    #!/usr/bin/expect -f spawn telnet 172.16.1.80 expect "login" { send "admin\n" ex ...

  3. 记录路径dp-4713-Permutation

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4713 题目大意: 题意同HDU 3092这不过这题要输出路径. 解题思路: 思路同HDU 3092. ...

  4. Struts2图片文件上传,判断图片格式和图片大小

    1. 配置Struts2能够上传的最大文件大小 使用Struts2进行文件上传的时候,Struts2默认文件大小最大为2MB,如果要传大一点的文件,就需要修改struts.xml配置文件,重新设置能够 ...

  5. Java学习JVM搞搞Jconsole呗

    无意间翻到这条博客:http://www.blogjava.net/zhvfeng/archive/2010/08/04/327956.html 这里还有个讲解的:http://www.kafka01 ...

  6. 【iOS开发-31】UITabBar背景、icon图标颜色、被选中背景设置以及隐藏UITabBar的两种方式

    一.对UITabBar背景和icon图标的一些设置 (1)由于直接给UITabBar设置的背景颜色显示的不纯.半透明的感觉,所以,有时候我们能够直接利用纯色的图片作为背景达到想要的效果. (2)给ic ...

  7. regsvr32 命令小集注册OCX控件,注册控件(包括十几个举例)

    Regsvr32 进程文件: regsvr32 or regsvr32.exe  进程名称: Microsoft DLL Registration Service  英文描述: regsvr32.ex ...

  8. 基于MMSeg算法的中文分词类库

    原文:基于MMSeg算法的中文分词类库 最近在实现基于lucene.net的搜索方案,涉及中文分词,找了很多,最终选择了MMSeg4j,但MMSeg4j只有Java版,在博客园上找到了*王员外*(ht ...

  9. JSP中两种include的区别

    首先说明这两种都是什么: <%@ include file=”relativeURI”%> 可以叫作静态include(静态包含),是jsp指令中的一种,(JSP指令控制JSP编译器如何去 ...

  10. lua 函数回调技巧

    技巧1: local a = {}; function b() print("Hello World") end a["sell"] = {callFunc = ...