2016-05-12 31 views
1
public class view extends View 
{ 
    public view(Context context) 
    { 
     super(context); 
    } 
    protected void onDraw(Canvas canvas) { 
     super.onDraw(canvas); 
     canvas.drawBitmap(thing1, 200, 200, null); 
     run(); 
    } 
    public void run() 
    { 
     try { 
      Thread.sleep(2000); 
     } catch(InterruptedException ex) { 
      Thread.currentThread().interrupt(); 
     } 
     if(tester2){ 
      thing1=BitmapFactory.decodeResource(getResources(), R.drawable.image2); 
      tester2=false; 
      invalidate(); 
     } 
     else 
     { 
      thing1=BitmapFactory.decodeResource(getResources(), R.drawable.image1); 
      tester2=true; 
      invalidate(); 
     } 
    } 
} 

这工作正常,但我得到“应用程序可能做了太多工作”的消息在日志中,并跳过一堆帧。我该如何解决?跳过#帧...应用程序可能在其主线程上做了太多工作。

+1

[该应用程序可能在其主线程上做了太多工作](http://stackoverflow.com/questions/14678593/the-application-may-be-doing-too-much-work-on - 它的-主线程) – settaratici

回答

1

确保您没有在主线程上运行run()方法,因为它会将整个UI暂停至少2000毫秒。在单独的线程上运行该方法。

相关问题