編輯:關於Android編程
一、功能:實現將圖片繞固定點旋轉,圈數隨機,onTouch後旋轉。
二、程序框架:
組成
功能
主Activity:MyActivity
1.實現animation
2.實現onTouch
View :MyView
1.將突破繪制到MyView上
三、程序源代碼:
MyVIew.java
package com.androids.kavinapps.myapplication; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.animation.Animation; import android.view.animation.RotateAnimation; /** * Created by Administrator on 14-11-29. */ public class MyView extends View{ //define roate animatioin public Animation mAnimationRoate; //define bitmap object Bitmap mBitmap = null; public MyView(Context context) { super(context); //load resource mBitmap = ((BitmapDrawable)getResources().getDrawable(com.androids.kavinapps.myapplication.R.drawable.choujiang1)).getBitmap(); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint mPaint = null; //draw pic canvas.drawBitmap(mBitmap,0,40,null); } }
package com.androids.kavinapps.myapplication; import android.app.Activity; import android.graphics.drawable.AnimationDrawable; import android.os.Bundle; import android.os.Message; import android.os.Handler;//Handler import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.animation.Animation; import android.view.animation.RotateAnimation; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; public class MyActivity extends Activity { AnimationDrawable mAnimation1 = null; int mRandom = 1;//隨機數 MyView myView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myView = new MyView(this); setContentView(myView); mRandom = (int) (Math.random()*100); if(mRandom%5==0){ mRandom = 5; }else { mRandom = mRandom%5; } myView.mAnimationRoate = new RotateAnimation(0.0f, +(1800.0f +72*mRandom), Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f); //set the time of anim myView.mAnimationRoate.setDuration(3000); myView.mAnimationRoate.setFillAfter(true);//動畫完成後不恢復原狀 myView.startAnimation(myView.mAnimationRoate); }//onCreate public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mRandom = (int) (Math.random()*100); if(mRandom%5==0){ mRandom = 5; }else { mRandom = mRandom%5; } myView.mAnimationRoate = new RotateAnimation(0.0f, +(1800.0f +72*mRandom), Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f); myView.mAnimationRoate.setDuration(3000); myView.mAnimationRoate.setFillAfter(true);//動畫完成後不恢復原狀 myView.startAnimation(myView.mAnimationRoate); return true; } return true; } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.my, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
1.如何產生隨機數
mRandom = (int) (Math.random()*100);2.如何使動畫完成後,不恢復原裝填
myView.mAnimationRoate.setFillAfter(true);//動畫完成後不恢復原狀
mBitmap = ((BitmapDrawable)getResources().getDrawable(com.androids.kavinapps.myapplication.R.drawable.choujiang1)).getBitmap();2014年12月9日14:41:34
概況 Android在4.3的版本中(即API 18)加入了NotificationListenerService,根據SDK的描述(AndroidDev
前段時間,我看到了一篇關於Android動畫的文章,十分喜歡文章作者的筆風,可惜每個人的筆風都不同,不過我倒是實現了一個類似的Switch組件,項目地址為https://
Android Activity各啟動模式的差異Activity共有四種啟動模式:standard,singleTop,singleTask,singleInstance
今天我們來接觸一下多線程下載,當然也包括斷點續傳,我們可以看到很多下載器,當開通會員的時候下載東西的速度就變得快了許多,這是為什麼呢?這就是跟今天講的多線程有關系了,其實