求大神们 给 解答
以前我就知道 J2ME里 Canvas画布重画 是 repaint(); 但是 现在安卓里 怎么都不行 找了个invalidate(); 但是还不行??? 为什么??--------------------编程问答-------------------- 方法一:
invalidate()
//实例化一个Handler对象,并重写handleMessage方法调用invalidate()实现界面刷新,在线程中通过sendMessage发送界面更新消息,
方法二:
postInvalidate()
//直接调用 --------------------编程问答-------------------- invalidate() 主线程中调用
postInvalidate() 非主线程调用更新。 --------------------编程问答-------------------- +1 --------------------编程问答--------------------
package com.j2men.tank;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.Log;
import android.view.View;
public class Tank_02 extends View implements Runnable{
Thread thread = new Thread();
Resources r = this.getResources();
Bitmap bm = BitmapFactory.decodeResource(r, R.drawable.tank_right03);
int x=10;
Paint p = new Paint();
public Tank_02(Context context) {
super(context);
// TODO Auto-generated constructor stub
this.thread.start();
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
canvas.drawBitmap(bm, x, 150, p);
}
public void run() {
// TODO Auto-generated method stub
while(true){
x++;
Log.v("sdsd","fsdfs");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {e.printStackTrace();
}
this.postInvalidate();
}
}
}
大家给审查下哪写的不对
--------------------编程问答-------------------- 本人Q764175747 可否给下你们的Q号 给解释下 谢谢 --------------------编程问答-------------------- There are some problems that arise when using postInvalidate from other threads (like not having the UI updated right-away), this will be more efficient:
runOnUiThread(new Runnable() {
public void run() {
myImageView.setImageBitmap(image);
imageView.invalidate();
}
});
补充:移动开发 , Android