Android CoordinatorLayout & Snackbar

下面連結為 Android 中 Snackbar 類別的 Java API Doc。
https://developer.android.com/reference/android/support/design/widget/Snackbar.html

其中提到 "They show a brief message at the bottom of the screen on mobile ..."。

 而我第一次遇上 Snackbar 是在 Tabbed Activity 的 Swipe 模式中。其中使用的是 CoordinatorLayout。那時我認為 Snackbar 的使用必須搭配 CoordinatorLayout。

但在看到上面的敘述,說 Snackbar 會顯示在螢幕底部,讓我想要一探究竟。到底是會出現在螢幕底部,還是跟著 CoordinatorLayout??

我在原 CoordinatorLayout 外,加了一層 LinearLayout,而在 CoordinatorLayout 後,隨便加了個 Button。結果就如下圖所示。



從圖中可以看出,Snackbar 出現在 CoordinatorLayout 的底部,而不是螢幕的底部。

寫到這邊,想到,如果沒有 CoordinatorLayout,Snackbar 是否就會出現在螢幕底部!?




留言

這個網誌中的熱門文章

泰文子音與字形之間的變化

GRI 準則解析 II

綠金 3.0 願景解析