电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術文章
文章詳情頁

android自定義view實現圓周運動

瀏覽:98日期:2022-09-20 13:44:26

本文實例為大家分享了android自定義view實現圓周運動的具體代碼,供大家參考,具體內容如下

android自定義view實現圓周運動

思想

自定義Animation,自己定義半徑,相當于原來控件的位置為(0,0),按照每個角度區間,計算新的位置,跟著時間變動

android自定義view實現圓周運動

逆時針轉動

public class VenusCircleAnimation extends Animation { private int radii; public VenusCircleAnimation(int radii) { this.radii = radii; } @Override protected void applyTransformation(float interpolatedTime, Transformation t) { //根據取值范圍 確定圓周運動的角度范圍。360-0 float 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-180 newAngle1 = 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-270 newAngle1 = 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-360 newAngle1 = 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; } @Override protected 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-180 newAngle1 = 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-270 newAngle1 = 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-360 newAngle1 = 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);

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Android
相關文章:
主站蜘蛛池模板: 屏蔽泵厂家,化工屏蔽泵_维修-淄博泵业 | 长沙网站建设制作「网站优化推广」-网页设计公司-速马科技官网 | 北钻固控设备|石油钻采设备-石油固控设备厂家 | 优秀的临床医学知识库,临床知识库,医疗知识库,满足电子病历四级要求,免费试用 | 扬州汇丰仪表有限公司 | 有福网(yofus.com)洗照片冲印,毕业聚会纪念册相册制作个性DIY平台 | 河南橡胶接头厂家,河南波纹补偿器厂家,河南可曲挠橡胶软连接,河南套筒补偿器厂家-河南正大阀门 | 合肥制氮机_合肥空压机厂家_安徽真空泵-凯圣精机 | 粉末冶金注射成型厂家|MIM厂家|粉末冶金齿轮|MIM零件-深圳市新泰兴精密科技 | 右手官网|右手工业设计|外观设计公司|工业设计公司|产品创新设计|医疗产品结构设计|EMC产品结构设计 | 考勤系统_考勤管理系统_网络考勤软件_政企|集团|工厂复杂考勤工时统计排班管理系统_天时考勤 | 电子万能试验机_液压拉力试验机_冲击疲劳试验机_材料试验机厂家-济南众标仪器设备有限公司 | 鼓风干燥箱_真空烘箱_高温干燥箱_恒温培养箱-上海笃特科学仪器 | 华禹护栏|锌钢护栏_阳台护栏_护栏厂家-华禹专注阳台护栏、楼梯栏杆、百叶窗、空调架、基坑护栏、道路护栏等锌钢护栏产品的生产销售。 | 天津蒸汽/热水锅炉-电锅炉安装维修直销厂家-天津鑫淼暖通设备有限公司 | 无线讲解器-导游讲解器-自助讲解器-分区讲解系统 品牌生产厂家[鹰米讲解-合肥市徽马信息科技有限公司] | 宝元数控系统|对刀仪厂家|东莞机器人控制系统|东莞安川伺服-【鑫天驰智能科技】 | ICP备案查询_APP备案查询_小程序备案查询 - 备案巴巴 | 药品冷藏箱厂家_低温冰箱_洁净工作台-济南欧莱博电子商务有限公司官网 | MVR蒸发器厂家-多效蒸发器-工业废水蒸发器厂家-康景辉集团官网 | 小程序开发公司-小程序制作-微信小程序开发-小程序定制-咏熠软件 | 法兰螺母 - 不锈钢螺母制造厂家 - 万千紧固件--螺母街 | 神超官网_焊接圆锯片_高速钢锯片_硬质合金锯片_浙江神超锯业制造有限公司 | HYDAC过滤器,HYDAC滤芯,现货ATOS油泵,ATOS比例阀-东莞市广联自动化科技有限公司 | 领先的大模型技术与应用公司-中关村科金 | 铝合金风口-玻璃钢轴流风机-玻璃钢屋顶风机-德州东润空调设备有限公司 | 飞行者联盟-飞机模拟机_无人机_低空经济_航空技术交流平台 | 耐力板-PC阳光板-PC板-PC耐力板 - 嘉兴赢创实业有限公司 | 长沙发电机-湖南发电机-柴油发电机供应厂家-长沙明邦智能科技 | 风信子发稿-专注为企业提供全球新闻稿发布服务 | CTAB,表面活性剂1631溴型(十六烷基三甲基溴化铵)-上海升纬化工原料有限公司 | 肉嫩度仪-凝胶测试仪-国产质构仪-气味分析仪-上海保圣实业发展有限公司|总部 | 铝镁锰板_铝镁锰合金板_铝镁锰板厂家_铝镁锰金属屋面板_安徽建科 | 湖南长沙商标注册专利申请,长沙公司注册代理记账首选美创! | 在线浊度仪_悬浮物污泥浓度计_超声波泥位计_污泥界面仪_泥水界面仪-无锡蓝拓仪表科技有限公司 | 冷凝水循环试验箱-冷凝水试验箱-可编程高低温试验箱厂家-上海巨为(www.juweigroup.com) | R507制冷剂,R22/R152a制冷剂厂家-浙江瀚凯制冷科技有限公司 | 上海办公室装修公司_办公室设计_直营办公装修-羚志悦装 | TPU薄膜_TPU薄膜生产厂家_TPU热熔胶膜厂家定制_鑫亘环保科技(深圳)有限公司 | loft装修,上海嘉定酒店式公寓装修公司—曼城装饰 | 吸音板,隔音板,吸音材料,吸音板价格,声学材料 - 佛山诺声吸音板厂家 |