android 应用程序线程内的 invalidate()

发布于 2024-10-10 16:05:50 字数 241 浏览 0 评论 0原文

我是机器人编程新手,但我在黑莓编程方面有相当多的经验。

我创建了一个具有活动类 (main.java) 和视图类 (game.java) 的应用程序。

在视图类中,我有一些位图被绘制到屏幕上。我创建了一个线程,并在线程中移动图像。但是,当我在线程内调用 invalidate() 时,它永远不会重绘屏幕。

您无法从线程中使屏幕无效吗?我知道线程正在运行并且正在调用 invalidate,它只是永远不会在屏幕上进行更改。

I'm new to programming androids but I have quite a bit of experience programming blackberries.

I created an app that has an activity class (main.java) and a view class (game.java).

Inside the view class I have some bitmaps being drawn to the screen. I created a thread and I'm moving the images around in the thread. However when I call invalidate() inside the thread it never redraws the screen.

Are you not able to invalidate() the screen from a thread? I know the thread is running and the invalidate is being called, it just never makes the changes on the screen.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

世界如花海般美丽 2024-10-17 16:05:50

您必须使用 View.postInvalidate()如果您从非 UI 线程调用它。
根据文档:

公共无效postInvalidate()
自:API 级别 1

导致事件循环的后续循环发生无效。使用它使非 UI 线程中的视图无效。

You have to use View.postInvalidate() if you call it from a non-UI thread.
According to docs:

public void postInvalidate ()
Since: API Level 1

Cause an invalidate to happen on a subsequent cycle through the event loop. Use this to invalidate the View from a non-UI thread.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文