我正在移植一个在图形环境下编写的应用程序,该环境允许绘图发生在剪辑矩形框之外。有没有在Android中实现这个功能的方法?
我正在移植一个在图形环境下编写的应用程序,该环境允许绘图发生在剪辑矩形框之外。有没有在Android中实现这个功能的方法?
尝试设置
android:clipChildren="false"
到父视图
要在画布的边界外绘制,您需要扩展画布的clipRect。
请查看Canvas类上重载的clipRect方法。
注意 - 您需要指定Region操作,因为默认操作是INTERSECT。因此,可以尝试以下内容:
Rect newRect = canvas.getClipBounds();
newRect.inset(-5, -5) //make the rect larger
canvas.clipRect (newRect, Region.Op.REPLACE);
//happily draw outside the bound now
onDraw(Canvas canvas)
中都这样做,那么你不是让计算机多做了很多额外的工作吗? - Someone Somewhere你可以在喜欢的位置绘制,但是超出剪切矩形的部分将不会被保存。
// in constructor/elsewhere
Rect newRect = new Rect();
// in onDraw
canvas.getClipBounds(newRect);
newRect.inset(0, -20); //make the rect larger
canvas.clipRect(newRect, Region.Op.REPLACE);
newRect
? - Anton MalmyginRegion.Op.REPLACE
已经被弃用,它不再起作用了! - Mohit Atray<TextView
...
android:shadowColor="#01000000"
android:shadowDx="100" // out of right bound
android:shadowDy="0"
android:shadowRadius="1"
.../>
使用类似@numan答案中的clipRect()不起作用,因为TextView在onDraw()中剪切自己的矩形:
if (mShadowRadius != 0) {
clipLeft += Math.min(0, mShadowDx - mShadowRadius);
clipRight += Math.max(0, mShadowDx + mShadowRadius);
clipTop += Math.min(0, mShadowDy - mShadowRadius);
clipBottom += Math.max(0, mShadowDy + mShadowRadius);
}
canvas.clipRect(clipLeft, clipTop, clipRight, clipBottom);
android:clipChildren="false"
和android:clipToPadding="false"
。