In this example, I try to invalidate only a rectangle of my custom view, but the canvas passed to onDraw is not clipped. Output always shows that the clip bounds contain the whole canvas. What's the reason for this?
public class ClippingActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new ClippingView(this));
}
}
class ClippingView extends View {
Rect r = new Rect();
public ClippingView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.getClipBounds(r);
Log.d("ClippingView","onDraw: " + r);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
invalidate(0,0,400,400);
return true;
}
}