WEB开发网
开发学院手机开发Android 开发 利用Handler来更新android的UI 阅读

利用Handler来更新android的UI

 2010-08-24 05:43:00 来源:WEB开发网   
核心提示:myView = new MyView(this);mHandler = new Handler();mHandler.post(update);setContentView(myView);}private Runnable update = new Runnable() {public void run() {my

myView = new MyView(this);

mHandler = new Handler();

mHandler.post(update);

setContentView(myView);

}

private Runnable update = new Runnable() {

public void run() {

myView.update();

mHandler.postDelayed(update, 5);

}

};

class MyView extends View{

private float x = 0f;

public MyView(Context context) {

super(context);

}

public void update(){

postInvalidate();

}

protected void onDraw(Canvas canvas) {

super.onDraw(canvas);

x+=1;

Paint mPaint = new Paint();

mPaint.setColor(Color.BLUE);

canvas.drawRect(x, 40, x+40, 80, mPaint);

}

}

上一页  1 2 3 

Tags:利用 Handler 更新

编辑录入:coldstar [复制链接] [打 印]
赞助商链接