2011-11-14 133 views
0
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); 
} 

我试图快速绘制活动位图,做什么快速绘制? (这是非常缓慢,不光滑)Android绘制快速位图

回答

0

,如果你正在使用View类来创建表面会很慢,所以使用SurfaceView。

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

Her e了解更多信息。

+0

啊谢谢我用surfaceview尝试,是光滑的,罚款,但我可以让surfaceview透明背景? – user1028269

+0

标记为答案,如果是。 –

+0

设置颜色透明0X00000000可以使视图透明。 –

1

您目前使用的手机功率太大。你需要让线程随时都睡觉。 40毫秒是给你25帧/秒的好时机。

这里有一个例子

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