无效()不记得的OnDraw方法不记得、方法、OnDraw

2023-09-07 10:29:46 作者:废途

无效()不记得我的的OnDraw()方法。我使用无效()在该的OnDraw()是同一个类中setter方法​​。

invalidate() dont recall my OnDraw() method. I use invalidate() in a setter method in the same class that OnDraw() is.

public class PuzzleDraw extends View {

    // defining some variables //

    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        // codes for painting puzzle //
    }

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

    // Method for giving cursor X/Y from MainActivity OnTouch() method and using it in OnDraw() method in some part of painting code //

    public void setCursor(int i, int j) {
        this.xx = i;
        this.yy = j;
        invalidate();
    } 

在调试我的code,万物是除了忆及好的OnDraw()无效()执行...事实上,无效()无所事事的我!哪里不对?我用 postInvalidate() this.invalidate() this.postInvalidate()过,但什么都没有改变。

when i debug my code, everythings is good except RECALLING OnDraw() when invalidate() executes... in fact, invalidate() doing nothing for me! what is wrong? I used postInvalidate(), this.invalidate(), this.postInvalidate() too, but nothing changed.

推荐答案

调用到无效()不会执行的onDraw 直接,它只设置相应的标志在查看类。你的的onDraw 方法将被框架在视图层次遍历下一次被调用。

Calling to invalidate() wouldn't execute onDraw directly, it only sets the appropriate flag in the View class. Your onDraw method will be called by framework the next time when view hierarchy is traversed.