【发布时间】:2015-07-10 19:26:04
【问题描述】:
我试图防止在我的应用程序中过度绘制,并且在其中一个根视图中我想检测我的子视图的位置,然后为它们不在的位置绘制背景。据我了解,剪辑会剪辑到路径之外,但我真正想做的不是在孩子所在的屏幕上的某些位置绘制。有什么好办法吗?
编辑: 所以我有一段时间没有玩画布了,但我想做这样的事情:
public class ContainerView extends FrameLayout {
private final Paint mBackgroundPaint = new Paint();
private final Path mPath = new Path();
public ContainerView(Context context, AttributeSet attrs) {
super(context, attrs);
mBackgroundPaint.setColor(context.getResources().getColor(R.color.default_background));
}
@Override protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawPaint(mBackgroundPaint);
mPath.reset();
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
mPath.addRect(child.getLeft(), child.getTop(), child.getRight(), child.getBottom(),
Path.Direction.CCW); // What direction do I want?
}
canvas.clipPath(mPath);
}
}
clipPath 只是不会做我想做的事,我不认为。我认为那会在路径外剪辑,我需要在路径内剪辑。
【问题讨论】: