android 左移动画_android旋转动画和平移动画详解,补充说一下如果制作gif动画放到csdn博客上...

先上效果图:

eb121fe056eeb90896468e55b492e7c1.gif

制作过程是先起一个模拟器,然后把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));

}

camera.rotateY(degrees); //这个Y轴旋转就是左右旋转

camera.getMatrix(matrix);

camera.restore();

matrix.preTranslate(-centerX, -centerY);

matrix.postTranslate(centerX, centerY);//这两句的意思是把View移到原点后旋转完再移动到现在的位置

}

}

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

如果是移动的话

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);

}

}

然后主程序这样来调用:

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);

}

});

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/503686.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

vm虚拟机安装包_一次Miniconda虚拟机安装的神奇踩坑记录

本人一直都是在物理机环境下使用Anaconda,好处是提供了比较完全的机器学习包,还有方便的虚拟环境,缺点是体积太大。但如果直接用Anaconda中的根目录环境作为pycharm中的Python解释器,因为在运行程序前会不断加载根目录中的Python包…

css3弧形跑道效果_Css 实现漂亮弧形

在实现页面五花八门的有特色的ui时,我们有时会遇到要用实现一个弧形,而这样的弧形要怎么实现呢?用图片?好像不大现实,因为这样就要无故多加载一张图片了,这里我们来说说怎么用css的after伪类来实现弧形。先…

python螺旋圆的绘制_python 使用turtule绘制递归图形(螺旋、二叉树、谢尔宾斯基三角形)...

插图工具使用Python内置的turtle模块,为什么叫这个turtle乌龟这个名字呢,可以这样理解,创建一个乌龟,乌龟能前进、后退、左转、右转,乌龟的尾巴朝下,它移动时就会画一条线。并且为了增加乌龟画图的艺术价值…

教室信息管理系统mysql_教师信息管理系统(方式一:数据库为oracle数据库;方式二:存储在文件中)...

方式一:运行截图数据库的sql语句:/*Navicat Oracle Data TransferOracle Client Version : 12.1.0.2.0Source Server : ORCZYTSource Server Version : 120100Source Host : localhost:1521Source Schema : C##ZYTTarget Server Type : ORACLETarget Ser…

mysql having ct_mysql中where和having子句的区别和具体用法

1.mysql中的where和having子句的区别having的用法having字句可以让我们筛选成组后的各种数据,where字句在聚合前先筛选记录,也就是说作用在group by和having字句前。而 having子句在聚合后对组记录进行筛选。SQL实例:1.1.显示每个地区的总人口…

Linux rcp命令教程:如何在远程主机和本地之间复制文件(附实例详解和注意事项)

Linux rcp命令介绍 rcp是remote copy的缩写,它是Linux系统中用于在本地主机和远程主机之间复制文件或目录的命令。虽然有更安全的方法(如scp或rsync)可以完成这项任务,但rcp命令让你以简单的方式在两台计算机之间复制文件&#x…

python圆形_Python中的圆形范围

非常感谢大家。在 我实现了我想要的crange(参考Ni和J.F.Sebastian)。在import math class crange: def __init__(self, start, stop, stepNone, moduloNone): if step 0: raise ValueError(crange() arg 3 must not be zero) if step is None and modul…

python实例化对象有new吗_PHP new:实例化对象

前面我们介绍了怎么定义一个类,但是我们要使用类中的属性和方法并不像使用变量和函数那样简单,首先要对类进行实例化才行,下面就来详细介绍一下。 实例化对象 将类实例化成对象非常容易,只需要使用new关键字并在后面加上一个和类名…

note.js和mysql的优劣_nginx与Node.js的优缺点是什么?

ngx相对node有这么几个较大的优点:1.性能更高,毕竟C写的,而且ngx的epoll是裸的,node的epoll是libuv封装的。2.完备的静态资源支持……这个就不说了,你用node写一个和ngx工作完全一致的静态资源库试试……当然npm上有现…

python实现xmind_Python xmind库(生成框架图)

小编在测试日常工作中遇到一个费时的问题,如何将excel中的测试用例,生成测试框架图?经过查阅发现的python xmind库 将excel中的测试用例,生成测试框架图,分为2步 1.解析excel,取出excel中数据(此…

pythondistutils安装_python – 与distutils / pip一起安装Bash完成

我创建了一个简单的Python模块,并希望用pip进行分发.我还想与模块一起安装Bash完成文件.我正在使用Python 2.7.1和pip 0.8.2安装模块.我有这个setup.py:setup(namejenkinsmon,version0.0.1,descriptionJenkins Job Monitor,long_descriptionopen(README.txt).read()…

python代码解读软件_5种带你轻松分析Python代码的软件库

通常,人们会使用两种速度来衡量某种编程语言的优劣,即:开发速度和执行速度。对于Python而言,大家往往受益的是它能够快速地编写代码,而忽略了它是否能够快速地运行,并及时完成既定的任务。因此,…

python try else_python try/except/else与递归

Python版本:2.7。操作系统:Windows 10 64位。在 注意:我找到了一种方法来解决下面描述的问题,它不使用try/except/else语句。我问下面的问题仅仅是因为我很好奇为什么代码的行为方式是这样的,以及是否有一种方法可以使…

python闭包怎么理解_Python:闭包的理解

很多函数型的语言都有闭包这一概念,比如python的兄弟js。人们刚听到闭包这一概念总会觉得它很晦涩,难以理解。其实不然,主要是他的名字起得太抽象了,让人误以为很难。下面举一个例子:#coding:utf-8def foo():nums [0]…

mac ssh客户端_Electerm for Mac(ssh客户端)

Electerm for Mac是一款功能强大的,作为终端或ssh / sftp客户端(类似于xshell)为一体的工具,支持多平台(linux,mac,win),还有自定义终端样式,全局/会话代理,将书签/主题/快速命令同步到github s…

alpine登陆mysql_如何构建一个php7-alpine的docker镜像

我花了大概一周的时间进行了各种踩坑及实验,最终得出了一份可以使用的dockerfile及compose内含如下支持php7mysql_pdopostgre_pdophpredisswoole(可选,如应用swoole,dockerfile及nginx的配置会有所变化)dockerfile分为两部分,一部…

armbian nginx 部署博客_通过Git将Hexo博客部署到服务器

本文首发于我的个人博客https://orxing.top,欢迎来访服务器是用的阿里云ECS CentOS,本来是用来部署WordPress的,后来接触了Hexo,就把Hexo直接部署到了GitHub pages和Coding Pages上,但是最近发现Coding pages经常抽风&…

shell把mysql每句导出_shell实现,将mysql每个存储过程导出为单个文件_MySQL

#shell实现,将mysql中存储过程代码直接导出为文件dbcn"mysql -h172.16.1.194 -uroot -p123456 ";dbBCReport_Sync_Executor;ii0;ct$dbcn -N -e " select count(1) from mysql.proc as p where 11 and p.db$db and p.type like P%;";mkdir -p /c…

python弹出窗口后卡死_python的tkinter模块GUI编程为啥用了while循环之后就会使得程序出现卡死未响应崩溃?...

这位同学,首先无代码无真相。只能在这里猜测一下,你在GUI界面中点击了某个按钮,调用的函数然后触发了某种while循环,这个时候前台GUI将“未响应”卡死。不过一旦调用函数的while循环结束,GUI界面将再次可用。 不使用线…

python 字符串格式化语法_Python基础语法--字符串格式化

PS:在学习到Python的字符串格式化一些个人的总结,利用字符串格式化可以更好的对代码结果进行格式化输出语法栗子 例子中通过接收用户输入的值,赋值给sex_input和age_input生成两个变量,并根据判断输出相应的语句,and是…