2016-03-03 101 views
0

我有一個自定義的線性佈局,我從中擴展。我已經調用setWIllNotCacheDrawing,但它不會工作。這裏是我的類:Android onDraw從來沒有叫

public class ClippedLinearLayout extends LinearLayout { 

public ClippedLinearLayout(Context context) { 
    super(context); 
    this.setWillNotCacheDrawing(false); 
} 

public ClippedLinearLayout(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    this.setWillNotCacheDrawing(false); 
} 

public ClippedLinearLayout(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    this.setWillNotCacheDrawing(false); 
} 

@Override 
protected void onDraw(Canvas canvas) { 
    Log.e("clipped?", "clipped?); 
    Path mPath = new Path(); 
    mPath.addCircle(50, 50, 50, Path.Direction.CCW); 
    canvas.clipPath(mPath, Region.Op.INTERSECT); 
    super.onDraw(canvas); 
} 

} 
+0

重寫'draw(Canvas)'或'dispatchDraw(Canvas)',一定要調用'super(canvas)'' – pskink

回答