Android的LunarLander例子似乎并没有使用'无效' [英] Android LunarLander example does not seem to use 'invalidate'

查看:114
本文介绍了Android的LunarLander例子似乎并没有使用'无效'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习在Android样本code中的LunarLander例如: HTTP ://developer.android.com/resources/samples/LunarLander/index.html

I am studying the LunarLander example in the Android sample code: http://developer.android.com/resources/samples/LunarLander/index.html

我百思不得其解,因为意见在几个地方的code使用'无效'触发重绘说。但我不能找到它在code。

I am puzzled because the comments say in several places that the code uses 'invalidate' to trigger redrawing. But I can't find it in the code.

更重要的是我认为,图纸上应在视图的OnDraw总会发生,而不是在一个线程内联别处。

More importantly I believe that drawing should always happen in a View's onDraw and not inline elsewhere in a thread.

有没有人研究了例子,对于自己为何无效(评论)不会被调用?

Has anyone studied that example and have comments about why invalidate() is not being called?

感谢您分享您的见解!

- 皮托

推荐答案

这不是在一个线程内联,但它是从一个线程调用。

It isn't inlined in a Thread but it is called from a Thread.

@Override
public void run() {
    while (mRun) {
        Canvas c = null;
        try {
            c = mSurfaceHolder.lockCanvas(null);
            synchronized (mSurfaceHolder) {
                if (mMode == STATE_RUNNING) updatePhysics();
                doDraw(c);
            }
        } finally {
            // do this in a finally so that if an exception is thrown
            // during the above, we don't leave the Surface in an
            // inconsistent state
            if (c != null) {
                mSurfaceHolder.unlockCanvasAndPost(c);
            }
        }
    }
}

图纸本身应该始终从一个线程调用,当你做二维图形...

The drawing itself should always be called from a Thread when you do 2D graphics...

这篇关于Android的LunarLander例子似乎并没有使用'无效'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆