安卓view圆周运动(逆时针和顺时针转动)
思想
自定义Animation,自己定义半径,相当于原来控件的位置为(0,0),按照每个角度区间,计算新的位置,跟着时间变动
逆时针转动
public class VenusCircleAnimation extends Animation {private int radii;public VenusCircleAnimation(int radii) {this.radii = radii;}@Overrideprotected void applyTransformation(float interpolatedTime, Transformation t) {//根据取值范围 确定圆周运动的角度范围。360-0float d = 360 * interpolatedTime;//interpolatedTime 取值范围 0-1,表示时间if (d > 360) { //算法二d = d-360;}int[] ps = getNewLocation((int) d, radii);//t.getMatrix().setTranslate(ps[0], ps[1]);}public int[] getNewLocation(int newAngle, int r) {int newAngle1;int newX = 0, newY = 0;if (newAngle >= 0 && newAngle <= 90) {// Math.PI/180得到的结果就是1°,然后再乘以角度得到角度newX = (int) ( - (r * Math.cos(newAngle * Math.PI / 180)));newY = (int) (r * Math.sin(newAngle * Math.PI / 180));} else if (newAngle >= 90 && newAngle <= 180) {// 90-180newAngle1 = 180 - newAngle;newX = (int) (r * Math.cos(newAngle1 * Math.PI / 180));newY = (int) (r * Math.sin(newAngle1 * Math.PI / 180));} else if (newAngle >= 180 && newAngle <= 270) {//180-270newAngle1 = 270 - newAngle;newX = (int) (r * Math.sin(newAngle1 * Math.PI / 180));newY = (int) ( - (r * Math.cos(newAngle1 * Math.PI / 180)));} else if (newAngle >= 270) {//270-360newAngle1 = 360 - newAngle;newX = (int) ( - (r * Math.cos(newAngle1 * Math.PI / 180)));newY = (int) ( - (r * Math.sin(newAngle1 * Math.PI / 180)));}return new int[]{newX, newY};}}
顺时针
public class CircleAnimation extends Animation {private int radii;public CircleAnimation(int radii) {this.radii = radii;}@Overrideprotected void applyTransformation(float interpolatedTime, Transformation t) {float d = 360 * interpolatedTime ;if (d > 360) {d = d - 360;}int[] ps = getNewLocation((int) d, radii);//t.getMatrix().setTranslate(ps[0], ps[1]);}public int[] getNewLocation(int newAngle, int r) {int newAngle1;int newX = 0, newY = 0;if (newAngle >= 0 && newAngle <= 90) {newX = (int) (r * Math.sin(newAngle * Math.PI / 180));newY = (int) ( - (r * Math.cos(newAngle * Math.PI / 180)));} else if (newAngle >= 90 && newAngle <= 180) {// 90-180newAngle1 = 180 - newAngle;newX = (int) (r * Math.sin(newAngle1 * Math.PI / 180));newY = (int) (r * Math.cos(newAngle1 * Math.PI / 180));} else if (newAngle >= 180 && newAngle <= 270) {//180-270newAngle1 = 270 - newAngle;newX = (int) ( - (r * Math.cos(newAngle1 * Math.PI / 180)));newY = (int) (r * Math.sin(newAngle1 * Math.PI / 180));} else if (newAngle >= 270 && newAngle <= 360) {//270-360newAngle1 = 360 - newAngle;newX = (int) ( - (r * Math.sin(newAngle1 * Math.PI / 180)));newY = (int) ( - (r * Math.cos(newAngle1 * Math.PI / 180)));}return new int[]{newX, newY};}
}
使用
CircleAnimation animationw = new CircleAnimation(m);animationw.setDuration(d);animationw.setRepeatCount(-1);animationw.setInterpolator(new LinearInterpolator());imageView.startAnimation(animationw);
安卓view圆周运动(逆时针和顺时针转动)相关推荐
- 安卓View — View (一)
目录 安卓View - View (一) 一. View的基础知识 1.什么是View 2.View的位置参数 3.MotionEvent 4.TouchSlop 5.VelocityTracker ...
- 对安卓View getLayoutParams和getLayoutParams理解错误的自我检讨
最近发现应用报了个bug: 从报错stackTrace里面可以发现是设置LayoutParams时设置了错误的类型导致强转失败,同事往下查发现可能是这部分代码逻辑引起的问题: 这段逻辑会遍历Colla ...
- 安卓 View 开发 绘制尺子
上图: Layout: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns: ...
- 安卓View可见,不可见,隐藏。
可见(visible) XML文件:android:visibility="visible" Java代码:view.setVisibility(View.VISIBLE); 不可 ...
- Python 小型项目大全 36~40
三十六.沙漏 原文:http://inventwithpython.com/bigbookpython/project36.html 这个可视化程序有一个粗糙的物理引擎,模拟沙子通过沙漏的小孔落下.沙 ...
- D3D11的简单字体
本篇的任务是要先学会混合和纹理才能够做到的. 这儿有几种方法能够在D3D11中实现字体显示,一个是学会使用微软想要我们使用的两个新的API,Direct2D和DirectWrite,实际上它们是很有用 ...
- NOIP2005 篝火晚会 解题报告
佳佳刚进高中,在军训的时候,由于佳佳吃苦耐劳,很快得到了教官的赏识,成为了"小教官".在军训结束的那天晚上,佳佳被命令组织同学们进行篝火晚会.一共有n个同学,编号从1到n.一开始, ...
- 向量几何在游戏编程中的使用
<1>简单的2-D追踪 -Twinsen编写 -本人水平有限,疏忽错误在所难免,还请各位数学高手.编程高手不吝赐教 -我的Email-address: popyy@netease.com ...
- Ophone平台2D游戏引擎实现——物理引擎(一)(二)
http://dev.10086.cn/cmdn/wiki/index.php?doc-view-4271.html http://dev.10086.cn/cmdn/wiki/index.php?d ...
最新文章
- HTTP项目1.0 -- HTTP协议基础知识
- linux nor flash 读写,9.2 NorFLASH读写实验——M25PExx
- 无法绑定由多个部分组成的标识符“System.Data.DataRowView”
- 通过对代码进行调试讲解缓冲区溢出原理
- 爱屋及乌 年轻投资者因喜爱Snapchat亏钱也买Snap股票
- httpModules 与 httpHandlers
- php 读取或导出到Excel / CSV (附utf8、gbk 编码转换)
- 【Spring】Spring Boot 和 Redis 常⽤操作
- leetcode 合并数组
- 微服务、容器、DevOps三者之间的关系你清楚吗?
- [译]Introducing ASP.NET vNext and MVC 6
- 大端模式、小端模式、网络字节顺序与主机字节顺序
- 我的五年百度博客文章列表
- Android禁止截屏
- Android 仿美拍,秒拍 ,视频封面选择.有图有真相.
- 最简便的方法搭建Hexo+Github博客,基于Next主题
- 尚筹网-前台-会员系统(springboot,springcloud 实战)
- 【03月13日】建筑材料行业的估值高度排名
- 购物网站(内容页面)
- 不懂技术自己也可以轻松制作App