我写了一个自定义Android视图,需要在其剪切边界之外绘制.
这就是我所拥有的:

这是当我点击一个按钮时发生的情况,例如右键:

如何防止下面的视图在我的"句柄"上绘制?
我项目中的一些相关伪代码如下.
我的自定义视图MyHandleView如下所示:
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Path p = mPath;
int handleWidth = mHandleWidth;
int handleHeight = mHandleHeight;
int left = (getWidth() >> 1) - handleWidth;
canvas.save();
// allow drawing out of bounds vertically
Rect clipBounds = canvas.getClipBounds();
clipBounds.inset(0, -handleHeight);
canvas.clipRect(clipBounds, Region.Op.REPLACE);
// translate up to draw the handle
canvas.translate(left, -handleHeight);
// draw my background shape
canvas.drawPath(p, mPaint);
canvas.restore();
}
Run Code Online (Sandbox Code Playgroud)
布局是这样的(我简化了一点):
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Main content of the SlidingUpPanel --> …Run Code Online (Sandbox Code Playgroud)