post方法究竟做了什麼? - What exactly does the post method do?

問題:

I've encountered a very weird feature. 我遇到了一個非常奇怪的功能。

When I'm trying to run an animation on the main thread, it does not start. 當我試圖在主線程上運行動畫時,它不會啓動。 When I run said animation using 當我使用運行所述動畫

getView().post(new Runnable() {
            @Override
            public void run() {
                getView().startAnimation(a);
            }
        });

It does start. 它確實開始了。

I've printed the CurrentThread before starting the animation and both print main . 我在開始動畫之前打印了CurrentThread並且都打印了main

Obviously, I am missing something here, as both should start the animation on the main thread... My guess is that as post adds the task to the queue, it starts at a more "correct time", but I would love to know what happens here at more depth. 顯然,我在這裏遺漏了一些東西,因爲兩者都應該在主線程上啓動動畫......我的猜測是,當post將任務添加到隊列中時,它會在更“正確的時間”開始,但我很想知道這裏發生的事情更深入。

EDIT: Let me clear things up - my question is, why starting the animation on post causes it to start, when starting the animation on the main thread does not. 編輯:讓我清楚一點 - 我的問題是,爲什麼在帖子上啓動動畫會導致它啓動,當在主線程上啓動動畫時沒有。


解決方案:

參考: https://stackoom.com/en/question/w4Pv
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章