imageView = (ImageView)findViewById(R.id.img);
imageView.setImageResource(R.drawable.aa);
// crash below into bitmap width and height > 0;
bitmap = Bitmap.createBitmap(imageView.getWidth(),imageView.getHeight(), Bitmap.Config.ARGB_8888);
canvas = new Canvas(bitmap);
// imageView.setImageBitmap(bitmap);
dw = imageView.getWidth();
dh = imageView.getHeight();
Log.e("bitmap", "bitmap" + imageView);
Log.e("canvas", "canvas" + canvas);
imageView.setOnTouchListener(this);
//imageView.setOnClickListener(this);
}
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
int x = (int) event.getX();
int y = (int) event.getY();
switch(action){
case MotionEvent.ACTION_DOWN:
if (x >= dh && x < (dh + bitmap.getWidth())
&& y >= dw && y < (dw + bitmap.getHeight())) {
}
break;
}
return true;
}
}
答案 0 :(得分:0)
碰撞时用下面的代码替换代码。
imageView.measure(0,0);
bitmap = Bitmap.createBitmap(imageView.getMeasuredWidth(),imageView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
此外:
dw = imageView.getMeasuredWidth();
dh = imageView.getMeasuredHeight();