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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

android旋转动画和平移动画具体解释,补充说一下假设制作gif动画放到csdn博客上...

發(fā)布時(shí)間:2024/4/14 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android旋转动画和平移动画具体解释,补充说一下假设制作gif动画放到csdn博客上... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

先上效果圖:


我這里用的是GifCam來制作的gif動(dòng)畫,能夠在http://download.csdn.net/detail/baidu_nod/7628461下載,

制作過程是先起一個(gè)模擬器,然后把GifCam的框拖到模擬器上面。點(diǎn)擊Rec的new先,然后點(diǎn)擊Rec,然后就save到本地成gif文件

這里做一個(gè)左右旋轉(zhuǎn)。上下旋轉(zhuǎn),和左右移動(dòng)的動(dòng)畫。先自己建立一個(gè)View的類,作為操作的對(duì)象:

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);}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);//width 300 height 300canvas.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();} }
左右旋轉(zhuǎn)動(dòng)畫:

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; }@Overridepublic void initialize(int width, int height, int parentWidth, int parentHeight) {super.initialize(width, height, parentWidth, parentHeight);mCamera = new Camera();}@Overrideprotected 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));}<span style="color:#ff0000;">camera.rotateY(degrees); //這個(gè)Y軸旋轉(zhuǎn)就是左右旋轉(zhuǎn)</span>camera.getMatrix(matrix);camera.restore();matrix.preTranslate(-centerX, -centerY);matrix.postTranslate(centerX, centerY);//這兩句的意思是把View移到原點(diǎn)后旋轉(zhuǎn)完再移動(dòng)到如今的位置} }


假設(shè)是上線旋轉(zhuǎn)就把camera.rotateY(degrees)改成camera.rotateX(degrees)


假設(shè)是移動(dòng)的話

<span style="color:#330033;">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; }@Overridepublic void initialize(int width, int height, int parentWidth, int parentHeight) {super.initialize(width, height, parentWidth, parentHeight);mCamera = new Camera();}@Overrideprotected 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);} }</span>

然后主程序這樣來調(diào)用:

final MyView myView = (MyView) findViewById(R.id.myview);Button btn = (Button) findViewById(R.id.btn_move);btn.setOnClickListener(new View.OnClickListener() {@Overridepublic 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() {@Overridepublic 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() {@Overridepublic void onClick(View v) {RotateLeftRightAnimation anim = new RotateLeftRightAnimation(0,180, v.getWidth() / 2, v.getHeight() / 2, 0, false);anim.setDuration(500);myView.startAnimation(anim);}});



總結(jié)

以上是生活随笔為你收集整理的android旋转动画和平移动画具体解释,补充说一下假设制作gif动画放到csdn博客上...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。