編輯:關於android開發
android自定義動畫注意是繼承Animation,重寫裡面的initialize和applyTransformation,在initialize方法做一些初始化的工作,在applyTransformation方法進行相應的軌陣變化即可!
直接上demo!
public class Rotate3dAnimation 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;
public Rotate3dAnimation(float fromDegrees, float toDegrees, float centerX,
float centerY, float depthZ, boolean reverse) {
mFromDegrees = fromDegrees;
mToDegrees = toDegrees;
mCenterX = centerX;
mCenterY = centerY;
mDepthZ = depthZ;
mReverse = reverse;
}
@Override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
mCamera = new Camera();
}
// 生成Transformation
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
final float fromDegrees = mFromDegrees;
// 生成中間角度
float degrees = fromDegrees
+ ((mToDegrees - fromDegrees) * interpolatedTime);
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);
camera.rotateY(mCenterY);
} else {
//camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
camera.rotateY(-mCenterY);
}
camera.rotateY(degrees);
// 取得變換後的矩陣
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
}
這是一個模仿3D旋轉動畫的效果,下面是調用方法,mSecondMenuLayout指的是要開始動畫的view
/**
*
* @param start 開始角度
* @param end 結束角度
*/
private void applyRotation(float start, float end) {
// 計算中心點
final float centerX = mSecondMenuLayout.getWidth() / 2.0f;
// final float centerY = mSecondMenuLayout.getHeight() /2.0f;
final Rotate3dAnimation rotation = new Rotate3dAnimation(start, end,
centerX, 360, 310.0f, true);
//設置動畫的持續時間
rotation.setDuration(1000);
//設置動畫完成後是否保留原樣
rotation.setFillAfter(false);
//設置動畫插補器
rotation.setInterpolator(new AccelerateDecelerateInterpolator());
//設置動畫監聽
rotation.setAnimationListener(mAnimListener);
mSecondMenuLayout.startAnimation(rotation);
}
自定義控件之圓頭像,自定義控件先上代碼: package com.andy.oschina_android.widget; import android.conten
3D圖片采集與展示(SurfaceView 自適應 Camera, 錄制視頻, 抽取幀), 最近在做一個3D圖片采集與展示。 主要功能為:自定義Camera(google
Android快樂貪吃蛇游戲實戰項目開發教程-06虛擬方向鍵(五)繪制方向鍵箭頭,android-06本系列教程概述與目錄:http://www.cnblogs.com/
Android接入微信支付完全解析,太全了~ 今天來聊聊,android中接入微信支付的需求,肯定有人會說,這多簡單呀,還在這裡扯什麼,趕快去洗洗睡吧~~ 那我就不