Android快速绘制Bitmaps

时间:2011-11-14 14:14:35

标签: android android-layout

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);
}

我尝试快速绘制可移动位图,如何快速绘制绘图? (它很慢而且不光滑)

2 个答案:

答案 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)

如果使用View类创建曲面,它将非常慢,因此请使用SurfaceView。

表面视图用于创建频繁变化的表面。

转到Her e了解详情。