国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

android自定義view實現(xiàn)圓周運動

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

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

android自定義view實現(xiàn)圓周運動

思想

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

android自定義view實現(xiàn)圓周運動

逆時針轉(zhuǎn)動

public class VenusCircleAnimation extends Animation { private int radii; public VenusCircleAnimation(int radii) { this.radii = radii; } @Override protected void applyTransformation(float interpolatedTime, Transformation t) { //根據(jù)取值范圍 確定圓周運動的角度范圍。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得到的結(jié)果就是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);

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

標簽: Android
相關(guān)文章:
主站蜘蛛池模板: 亚洲精品15p | 成人网18免费网站在线 | 在线成人aa在线看片 | 91久热| 久久亚洲精品永久网站 | 成人久久18网站 | 国产午夜精品理论片 | 国产成人性色视频 | 国产一级毛片一区二区三区 | 亚洲成人精品久久 | 91精品观看91久久久久久 | 国产玖玖玖精品视频 | 国产第一夜 | 国产毛片久久国产 | 日黄网站| 国产精品爱久久久久久久9999 | 九九视频精品全部免费播放 | 美女网站免费观看视频 | 久草在线视频免费播放 | 免费99视频 | 亚洲国产精品aaa一区 | 99爱视频精品免视看 | 日韩美一区二区三区 | 男女无遮挡拍拍拍免费1000 | 国产在线观看精品香蕉v区 国产在线观看免费人成小说 | 99久久精品免费看国产一区二区 | 在线视频免费国产成人 | 51国产偷自视频区视频手机播器 | 中国黄色网址大全 | 曰本女同互慰高清在线观看 | 国产福利拍拍拍 | 99久久国产综合精品1尤物 | 天天拍拍夜夜出水 | 欧美精品日日鲁夜夜添 | 久久厕所视频 | 欧美一级va在线视频免费播放 | 2022国产91精品久久久久久 | 日韩亚洲精品不卡在线 | 国产精品亚洲精品爽爽 | 自拍国内 | 日韩制服诱惑 |