Bitmap top;
int x;
public ViewExample() {
top = BitmapFactory.decodeResource(getResources(), R.drawable.top);
Thread thread = new Thread(){
public void run(){
while(true){
x++;
postInvalidate();
}
}
};
thread.start();
}
@Override
protected void onDraw(Canvas c) {
c.drawBitmap(top, x, 0, null);
}
我尝试快速绘制可移动位图,如何快速绘制绘图? (它很慢而且不光滑)
答案 0 :(得分:1)
您目前使用的手机功率太大了。你需要让线程不时地睡觉。 40毫秒是给你25 fps的好时光。
下面是一个例子
public ViewExample() {
top = BitmapFactory.decodeResource(getResources(), R.drawable.top);
Thread thread = new Thread(){
public void run(){
while(true){
x++;
postInvalidate();
try
{
Thread.sleep(40);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
thread.start();
}
答案 1 :(得分:0)