編輯:初級開發
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.vIEw.Window;
import android.vIEw.WindowManager;
public class StartVIEw extends Activity
{
private static final int REFRESH = 0x000001;
/* 聲明GameVIEw類對象 */
private GameView mGameVIEw = null;
Handler myHandler = new Handler() {
//接收到消息後處理
public void handleMessage(Message msg)
{
switch (msg.what){
case StartVIEw.REFRESH:
//刷新
//注意這裡的刷新界面實際上是在UI 線程中執行的 不是另外開啟一個線程這裡要搞清楚
mGameVIEw.invalidate();
break;
}
super.handleMessage(msg);
}
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
//設置全屏
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.TYPE_STATUS_BAR,
WindowManager.LayoutParams.TYPE_STATUS_BAR);
super.onCreate(savedInstanceState);
setContentVIEw(R.layout.main);
/* 實例化GameVIEw對象 */
this.mGameView = new GameVIEw(this);
//設置顯示為我們自定義的View(GameVIEw)
setContentView(mGameVIEw);
//開啟線程
new Thread(new GameThread()).start();
}
public class GameThread implements Runnable
{
public void run()
{
while (!Thread.currentThread().isInterrupted())
{
Message message = new Message();
message.what = StartVIEw.REFRESH;
//發送消息
StartVIEw.this.myHandler.sendMessage(message);
try
{
Thread.sleep(100);
}
catch (InterruptedException e)
{
Thread.currentThread().interrupt();
}
}
}
}
}
二、 GameVIEw類:
package CityLife.VIEw;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Paint.Style;
import android.view.VIEw;
public class GameView extends VIEw
{
int startDrawBgX, startDrawBgY;
int startProgressX,startProgressY;
int startRectX ,startRectY ;
int rectW , rectH;
Bitmap bmpStartBg;
Bitmap bmpProgressBar;
public GameVIEw(Context context)
{
super(context);
bmpStartBg = BitmapFactory.decodeResource(getResources(), R.drawable.startbg);
startDrawBgY = (480 - bmpStartBg.getHeight()) / 2 - 40;
startDrawBgX = (320 - bmpStartBg.getWidth()) / 2;
//
bmpProgressBar = BitmapFactory.decodeResource(getResources(), R.drawable.progressbg);
startProgressY = (480 - bmpProgressBar.getHeight()) / 2 - 15;
startProgressX = (320 - bmpProgressBar.getWidth()) / 2;
//
startRectX = startProgressX;
startRectY = startProgressY;
rectW = startProgressX+bmpProgressBar.getWidth();
rectH = startProgressY+bmpProgressBar.getHeight();
// TODO Auto-generated constructor stub
}
public void onDraw(Canvas canvas)
{
if(startRectX < startProgressX + bmpProgressBar.getWidth())
{
startRectX = startRectX + 2;
}
else
{
}
//首先定義一個paint
Paint paint = new Paint();
paint.setColor(UsedColor.startBgColor);
// 設置樣式-填充
paint.setStyle(Style.FILL);
// 繪制一個矩形
canvas.drawRect(new Rect(0, 0, getWidth(), getHeight()), paint);
/********繪圖**************/
//輸出背景圖片
canvas.drawBitmap(bmpStartBg, startDrawBgX, startDrawBgY, paint);
canvas.drawBitmap(bmpProgressBar, startProgressX, startProgressY, paint);
paint.setColor(UsedColor.progressBgColor);
canvas.drawRect(new Rect(startRectX, startRectY, rectW, rectH), paint);
}
本文收集10款對開發者有用的Android應用,希望能對你的開發有所幫助。如果你還知道有其他對開發者很有用的android應用?也分享出來吧。列表如下:1.Remote
大家用eclipse調試android程序的時候可能遇到過不能顯示中文的問題,但有的時候顯示中文是非常必要的,尤其是對網絡數據進行解析的時候。這裡我給大家介紹一個簡單方
之前采用聊天敲門的方式來介紹Socket通信,有兩個不足的地方,1.服務器會造成IO的阻塞即服務器一旦執行server.accept();將一直處於阻塞狀態,直到有客戶
冬天,北風吹著、雪花飄著,宅男宅女都窩在被窩裡不願出去,但是又想用電腦上個網,看看動漫、打打游戲啥的……鑽出被窩就意味著寒冷,待在被窩裡就意味著不能玩台式電腦……真的是