先上效果图:

我这里用的是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. nohup命令与&区别,jobs,fg,bg,Ctrl-Z、Ctrl-C、Ctrl-D

    &方式: Unix/Linux下一般想让某个程序在后台运行,很多都是使用 & 在程序结尾来让程序自动运行.比如我们要运行mysql在后台:          /usr/local/my ...

  2. hdu1114

    完全背包的水题,不过今天才学动态规划,就这样啦……hahahah!!! 完全背包跟普通背包的区别是普通背包从后往前循环,以防止被替换 完全背包是从前往后循环,后面的状态会跟着之前状态的改变而改变…… ...

  3. NumberFormat 类

    NumberFormat 表示数字的格式化类, 即:能够依照本地的风格习惯进行数字的显示. 此类的定义例如以下: public abstract class NumberFormat extends ...

  4. VC实现文件拖拽OnDropFiles

    文章转自http://blog.csdn.net/zamaolangzi/article/details/5645284 使用过QQ的人都知道,只要把文件拖拽到消息框中就可以传送文件了.那么这种功能是 ...

  5. 14.2.5.5 Change Buffer

    14.2.5.5 Change Buffer change buffer是一个指定的数据结构 用于caches 数据到secondary index pages 当影响的pages 不是在buffer ...

  6. 使用CUNIT测试

    使用CUNIT测试 一:概述 CUnit是一个c语言的单元测试框架,它是以静态链接库的形式,连接到用户代码中的,主要的功能就是提供了语义丰富的断言和多种测试结果输出接口,可以方便地生成测试报告. 但是 ...

  7. Unicode 字符集与它的编码方式

    正式内容開始之前,我们先来了解一个基本概念,编码字符集. 编码字符集:编码字符集是一个字符集,它为每个字符分配一个唯一数字.Unicode 标准的核心是一个编码字符集,字母"A"的 ...

  8. [to do list][PCB][questions]and[plan]

    Questions 2014/5/29 1.最后检查布板,除了用netlist查,还有没有更快的方法? 2014/6/8 1.      R的location中心究竟是哪个? watermark/2/ ...

  9. BZOJ 3211 弗洛拉前往国家 树阵+并检查集合

    标题效果:给定一个序列,它提供了以下操作: 1.将[l.r]每个号码间隔a[i]变sqrt(a[i]) 2.查询[l,r]间隔和 剧烈的变化不支持由间隔,因此,我们选择单 - 点更换间隔查询的树阵,但 ...

  10. ISO/OSI网络体系结构和TCP/IP协议模型

    1. ISO/OSI的参考模型共有7层,由低层至高层分别为:物理层.数据链路层.网络层.传输层.会话层.表示层.     应用层.各层功能分别为: (1)物理层          提供建立.维护和拆除 ...