Invalidate()没有调用draw()

时间:2014-07-09 05:12:02

标签: java android

Invalidate()没有调用draw()..................

我在无效时使用了class object和imageview。

当使用类名调用invalidate()时会出错。

这些是我的课程。

请帮忙。

 public class DrawingClass extends View {
       Bitmap bitmap;
       Canvas canvas;
       Paint paint;
public DrawingClass(Context context,ImageView img) {
    super(context);
    bitmap = Bitmap.createBitmap(480, 800,
            Bitmap.Config.ARGB_8888);
    canvas = new Canvas(bitmap);
    canvas.drawColor(Color.CYAN);
    paint = new Paint();
    paint.setColor(Color.RED);
    img.setImageBitmap(bitmap);
    // TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
     super.onDraw(canvas);
    System.out.println("++++++++++inside on drwaw()");
     Paint paint = new Paint();
    paint.setColor(Color.GREEN);
     paint.setStrokeWidth(6);
    canvas.drawLine(50, 50, 300, 400, paint);
       }
     }

    public class AddOnClick extends Activity implements OnTouchListener{
ImageView imageView;
DrawingClass draw_cls;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.addstore_2);
    imageView=(ImageView)findViewById(R.id.imageView1);
    draw_cls=new DrawingClass(this,imageView);
    imageView.setOnTouchListener(this); 
}
@Override
public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub
    int action = event.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:   
        draw_cls.invalidate();
                 // imageView.invalidate();
    }
    return true;
}

}

0 个答案:

没有答案