Android view刷新

public class PuzzleView extends SurfaceView implements SurfaceHolder.Callback{  
    private SurfaceHolder surfaceHolder;  
 
    public PuzzleView(Context context){  
      //....  
      surfaceHolder = this.getHolder();//获取holder     
      surfaceHolder.addCallback(this);  
    }  
 
    protected void paint(Canvas canvas) {  
      //这里的代码跟继承View时OnDraw中一样  
    }  
 
    public void repaint() {   
       Canvas c = null;   
       try {   
         c = surfaceHolder.lockCanvas();   
         paint(c);   
       } finally {   
         if (c != null) {   
           surfaceHolder.unlockCanvasAndPost(c);   
         }   
       }   
    }   

你可能感兴趣的:(Android view刷新)