Mar*_*ark 24 android drawing image-clipping
我正在移植一个在图形环境中编写的应用程序,允许绘图发生在剪切矩形的边界之外.在Android中有什么办法吗?
num*_*ati 45
要在边界外绘制,您需要展开画布的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
Run Code Online (Sandbox Code Playgroud)
Dan*_*Vus 35
试着设定
android:clipChildren="false"
Run Code Online (Sandbox Code Playgroud)
到父视图
@numan 给出的答案几乎没问题,问题是这种方法的内存分配,所以我们应该这样做:
// 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);
Run Code Online (Sandbox Code Playgroud)
这解决了问题:-)
| 归档时间: |
|
| 查看次数: |
20664 次 |
| 最近记录: |