爲什麼使用片段,何時使用片段而不是活動? - Why fragments, and when to use fragments instead of activities?

問題:

In Android API 11+, Google has released a new class called Fragment .在 Android API 11+ 中,Google 發佈了一個名爲Fragment的新類。

In the videos, Google suggests that whenever possible ( link1 , link2 ), we should use fragments instead of activities, but they didn't explain exactly why.在視頻中,Google 建議在可能的情況下( link1link2 ),我們應該使用片段而不是活動,但他們沒有確切解釋原因。

What's the purpose of fragments and some possible uses of them (other than some UI examples that can be easily be achieved by simple views/layouts)?片段的目的是什麼以及它們的一些可能用途(除了一些可以通過簡單視圖/佈局輕鬆實現的 UI 示例)?

My question is about fragments:我的問題是關於片段:

  1. What are the purposes of using a fragment?使用片段的目的是什麼?
  2. What are the advantages and disadvantages of using fragments compared to using activities/views/layouts?與使用活動/視圖/佈局相比,使用片段的優缺點是什麼?

Bonus questions:獎金問題:

  1. Can you give some really interesting uses for fragments?你能給片段提供一些非常有趣的用途嗎? Things that Google didn't mention in their videos?谷歌在他們的視頻中沒有提到的事情?
  2. What's the best way to communicate between fragments and the activities that contain them?在片段和包含它們的活動之間進行通信的最佳方式是什麼?
  3. What are the most important things to remember when you use fragments?使用片段時要記住的最重要的事情是什麼? Any tips and warnings from your experience?您的經驗有什麼提示和警告嗎?

解決方案:

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