Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在编写一个动画的自定义视图。View 通过将 getContext() 方法转换为 Activity 然后调用 Activity.runOnUiThread 来访问其父 Activity 会更好,还是简单地使用处理程序并发布 View.invalidate 消息会更好?
更简单的方法 - 调用视图的 postInvalidate 方法。这可以在非 ui 线程上调用。
要么工作。IIRC runOnUiThread() 无论如何都会发布,runnable 稍后会被系统循环器拾取。所以对你来说更容易。在这种情况下,IMO,runOnUiThread 听起来更容易/更干净。