日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

android 动画x轴旋转,Android Roate3dAnimation实现围绕y轴竖直方向或者绕x轴方向旋转的3d动画效果...

發布時間:2023/11/27 生活经验 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 动画x轴旋转,Android Roate3dAnimation实现围绕y轴竖直方向或者绕x轴方向旋转的3d动画效果... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

概要:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Roate3dAnimation 實現了圍繞y軸豎直方向 或者繞x軸方向旋轉的3d動畫效果。這個例子來

自Android APIDemo中的一個自定義View動畫。他的實現展示自定義View動畫的基本步驟。

主要是重寫initialize方法,applyTransformation方法。

分析:

在Roate3dAnimation中,我們使用Android.graphic.Camera實現3d效果。

對Camera不熟悉的可看看?android.graphic.Camera?。

public?class?Rotate3dAnimation?extends?Animation?{

//開始角度

private?float?startDegree;

//結束角度

private?float?endDegree;

/**

*?這個旋轉動畫圍繞在2D空間的中心點執行.你可以用X軸坐標(叫做centerX)和Y軸(叫做centerY)

*?坐標來定義這個中心點

*/

private?float?centerX;

private?float?centerY;

/**

*?控制鏡頭景深,不需要的話給0值即可

*?mReverse?為true,表示反方向,false?表示正方向

*/

private?float?deepZ;

private?boolean?mReverse;

//用于輔助實現3d效果。

private?Camera?mCamera;

//X軸方向,或Y軸方向

enum?DIRECTION?{

X,?Y

}

DIRECTION?direction?=?DIRECTION.Y;

Rotate3dAnimation(float?fromDegree,?float?toDegree,?float?centerX,

float?centerY,?float?deepZ,?boolean?reverse)?{

this.startDegree?=?fromDegree;

this.endDegree?=?toDegree;

this.centerX?=?centerX;

this.centerY?=?centerY;

this.deepZ?=?deepZ;

this.mReverse?=?reverse;

}

Rotate3dAnimation(float?fromDegree,?float?toDegree,?float?centerX,

float?centerY,?float?deepZ,?boolean?reverse,?DIRECTION?direction)?{

this.startDegree?=?fromDegree;

this.endDegree?=?toDegree;

this.centerX?=?centerX;

this.centerY?=?centerY;

this.deepZ?=?deepZ;

this.mReverse?=?reverse;

this.direction?=?direction;

}

@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)?{

super.applyTransformation(interpolatedTime,?t);

float?fromDegree?=?startDegree;

float?degree?=?fromDegree?+?(endDegree?-?startDegree)?*?interpolatedTime;

final?Matrix?matrix?=?t.getMatrix();

mCamera.save();

if?(mReverse)?{

mCamera.translate(0,?0,?deepZ?*?interpolatedTime);

}?else?{

mCamera.translate(0,?0,?deepZ?*?(1?-?interpolatedTime));

}

if?(direction?==?DIRECTION.Y)?{

mCamera.rotateY(degree);

}?else?{

mCamera.rotateX(degree);

}

mCamera.getMatrix(matrix);

mCamera.restore();

matrix.preTranslate(-centerX,?-centerY);

matrix.postTranslate(centerX,?centerY);

}

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

應用:

iv_content.post(new?Runnable()?{

@Override

public?void?run()?{

Rotate3dAnimation?rotate3dAnimation?=?new?Rotate3dAnimation(0,?360,?iv_content.getWidth()/2,

0,?0,?true,?Rotate3dAnimation.DIRECTION.Y);

rotate3dAnimation.setDuration(3000);

iv_content.setAnimation(rotate3dAnimation);

rotate3dAnimation.start();

}

});

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

小奮斗文章

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

總結

以上是生活随笔為你收集整理的android 动画x轴旋转,Android Roate3dAnimation实现围绕y轴竖直方向或者绕x轴方向旋转的3d动画效果...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。