gpt4 book ai didi

android - 为什么 Canvas 在onDraw中没有被裁剪?

转载 作者:行者123 更新时间:2023-11-30 02:57:28 25 4
gpt4 key购买 nike

在这个例子中,我尝试只使自定义 View 的一个矩形无效,但是传递给 onDraw 的 Canvas 没有被剪裁。输出始终显示剪辑边界包含整个 Canvas 。这是什么原因?

public class ClippingActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new ClippingView(this));
}
}

class ClippingView extends View {

Rect r = new Rect();

public ClippingView(Context context) {
super(context);
}

@Override
protected void onDraw(Canvas canvas) {
canvas.getClipBounds(r);
Log.d("ClippingView","onDraw: " + r);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
invalidate(0,0,400,400);
return true;
}
}

最佳答案

我刚发现一个密切相关的问题:Partial invalidation in custom Android view with hardware acceleration

Romain Guy 回答说:

Partial redraw works just fine, only the specified region of the screen will get redrawn. What it won't do however is change the clip bounds on the Canvas. All the drawing operations will be recorded but only the ones intersecting with the dirty region will actually be executed.

关于android - 为什么 Canvas 在onDraw中没有被裁剪?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23042061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com