Android onDraw从未调用过

时间:2016-03-03 19:04:42

标签: android view android-custom-view

我有一个自定义线性布局,我可以从中扩展。我已经调用了setWIllNotCacheDrawing但它不会工作。这是我的班级:

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);
}

}

1 个答案:

答案 0 :(得分:0)

您正在扩展ViewGroup,有时默认情况下它们不会绘制。您是否尝试过在构造函数中调用View.setWillNotDraw(false)