代码如下:package wyf.ytl;import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;public class MyVeiw extends View{
Bitmap myBitmap;
Paint paint;
public MyVeiw(Context context, AttributeSet attrs) {
super(context, attrs);
this.initBitmap();
// TODO Auto-generated constructor stub
}
private void initBitmap() {
paint =new Paint();
myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.img);
// TODO Auto-generated method stub

}
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
paint.setAntiAlias(true);
}
}执行顺序是什么??
个人觉得应该先MyVeiw,然后initBitmap,最后onDraw...
这样的话问题是onDraw哪里被调用了。。不是这样的话又是如何执行的!请高手帮忙

解决方案 »

  1.   

    onDraw 是view 留给你的方法这个基本的java问题,上层会调用,你只要把你想要的功能加进去就好。
      

  2.   


    哥。上层调用。。你是指这里?super(context, attrs);?
    问题是上层调用了也是再this.initBitmap();之前。。
    变量paint没有new可用?请解释的清楚点谢谢。带上执行顺序。。
      

  3.   

    void android.view.View.invalidate()
    Invalidate the whole view. If the view is visible, onDraw will be called at some point in the future. This must be called from a UI thread. To call from a non-UI thread, call postInvalidate().
      

  4.   

    extends View
    你继承了view类onDraw 自然就会执行。你要看谁先执行,直接打印一些数据看看就知道了。
      

  5.   


    调用invalidate()会进ondraw()方法