先上效果图:

我这里用的是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. <转载>CSS解决图片过大撑破DIV的方法

    DIV+CSS网页内容中如果插入大于DIV层宽度显示,过大的图片将会撑破网页宽度显示从而网页严重变形,您是否遇到过?这里DIVCSS5给大家介绍几种解决图片撑破撑开网页DIV层方法. 图片撑破宽度解决 ...

  2. uva 1346 - Songs(贪心)

    题目链接:uva 1346 - Songs 题目大意:John Doe 是一个著名的DJ,现在他有n首播放个曲, 每首歌曲有识别符key,歌曲长度l,以及播放频率q.想在John Doe 想将磁带上的 ...

  3. javascript事件委托,事件代理,元素绑定多个事件之练习篇

    <ul id="parent-list"> <li id="post-1">item1</li> <li id=&qu ...

  4. Redis核心解读:集群管理工具(Redis-sentinel)

    Redis核心解读:集群管理工具(Redis-sentinel) - Redis - TechTarget数据库 Redis核心解读:集群管理工具(Redis-sentinel)

  5. 与众不同 windows phone (17) - Graphic and Animation(画图和动画)

    原文:与众不同 windows phone (17) - Graphic and Animation(画图和动画) [索引页][源码下载] 与众不同 windows phone (17) - Grap ...

  6. linux 配置 mail server

    一.配置yum安装工具 ①  进入yum目录 [root@bj ~]# cd /etc/yum.repos.d ②  配置yum.repo [root@bj yum.repos.d]# cprhel- ...

  7. WPF入门介绍

    Windows Vista已经于2007年1月30正式发行零售版本,安装Vista的计算机将会大量出现.在Vista时代,身为编程员,就一定要具备Vista桌面应用开发的能力.而开发Vista桌面应用 ...

  8. 最想做的三个Delphi项目:Paint,IM,SQL,另外还有Smart,TMS,FMX,UML,FreePascal,Python4Delphi,Cheat Engine

    都是绝美项目- 如果有时间,要做的项目:0. 整整5个Cloud项目(可带来商业收益,其中还包括手机发送, S/D/N/L/NetDriver)1. Heidi/front/SQLITE STUDIO ...

  9. 44个JAVA代码质量管理工具(转)

    1. CodePro AnalytixIt’s a great tool (Eclipse plugin) for improving software quality. It has the nex ...

  10. Unix文本处理工具之awk

    Unix命令行下输入的命令是文本,输出也都是文本.因此,掌握Unix文本处理工具是很重要的一种能力.awk是Unix常用的文本处理工具中的一种,它是以其发明者(Aho,Weinberger和Kerni ...