Android onDraw 从未调用过
Android onDraw never called
我有一个可以扩展的自定义线性布局。我已经调用了 setWIllNotCacheDrawing,但它不起作用。这是我的 Class:
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);
}
}
您正在扩展一个 ViewGroup,但有时默认情况下它们不会绘制。您是否尝试过在构造函数中调用 View.setWillNotDraw(false)?
我有一个可以扩展的自定义线性布局。我已经调用了 setWIllNotCacheDrawing,但它不起作用。这是我的 Class:
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);
}
}
您正在扩展一个 ViewGroup,但有时默认情况下它们不会绘制。您是否尝试过在构造函数中调用 View.setWillNotDraw(false)?