編輯:關於Android編程
先上效果圖:
我這裡用的是GifCam來制作的gif動畫,可以在http://download.csdn.net/detail/baidu_nod/7628461下載,<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+1sbX97n9s8zKx8/IxvDSu7j2xKPE4sb3o6zIu7rzsNFHaWZDYW21xL/yzc+1vcSjxOLG98nPw+ajrLXju/dSZWO1xG5ld8/Io6zIu7rzteO791JlYyzIu7rzvs1zYXZltb2xvrXYs8lnaWbOxLz+PC9wPgo8cD7V4sDv1/bSu7j21/PT0tD916qjrMnPz8LQ/deqo6y6zdfz09LSxravtcS2r7uto6zPyNfUvLq9qMGi0ru49lZpZXe1xMDgo6zX986qstnX97XEttTP8zo8L3A+CjxwPjwvcD4KPHByZSBjbGFzcz0="brush:java;">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);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//width 300 height 300
canvas.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();
}
}
左右旋轉動畫:
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; } @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) { 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)); } camera.rotateY(degrees); //這個Y軸旋轉就是左右旋轉 camera.getMatrix(matrix); camera.restore(); matrix.preTranslate(-centerX, -centerY); matrix.postTranslate(centerX, centerY);//這兩句的意思是把View移到原點後旋轉完再移動到現在的位置 } }
如果是移動的話
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; } @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) { 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); } }
final MyView myView = (MyView) findViewById(R.id.myview); Button btn = (Button) findViewById(R.id.btn_move); btn.setOnClickListener(new View.OnClickListener() { @Override public 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() { @Override public 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() { @Override public void onClick(View v) { RotateLeftRightAnimation anim = new RotateLeftRightAnimation(0, 180, v.getWidth() / 2, v.getHeight() / 2, 0, false); anim.setDuration(500); myView.startAnimation(anim); } });
前言Universal-Image-Loader,android-Volley,Picasso、Fresco和Glide五大Android開源組件加載網絡圖片比較。在An
功能1、顯示加載視圖,加載失敗的時候顯示加載失敗視圖,數據為空時顯示數據為空視圖,支持為失敗視圖設置點擊事件重新加載數據。2、支持個性化設置,自定義設置 加載、失敗、空數
目前Android平台上進行人臉特征識別非常火爆,本人研究生期間一直從事人臉特征的處理,所以曾經用過一段ASM(主動形狀模型)提取人臉基礎特征點,所以這裡采用JNI的方式
日志是任何項目開發中的必須組件,它可以記錄下來系統的行為,幫助開發者排錯,優化系統性能調整系統行為等.既然日志可以幫助我們做很多分析,那麼開發者肯定是有很多定制需求的,例