次のレイアウトファイルをActivity
でsetContentView()
に渡すとどうなるでしょうか。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/linear_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view" android:scrollbars="vertical" android:layout_width="match_parent" android:layout_height="match_parent" /> <android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal|bottom" android:layout_marginBottom="32dp" android:src="@drawable/ic_add_white_36dp" /> </LinearLayout>
RecyclerView
が画面全体に表示され、画面下辺から32dp
上にFloatingActionButton
が表示されるRecyclerView
が画面全体に表示され、画面中央にFloatingActionButton
が表示されるRecyclerView
のみが表示されるFloatingActionButton
のみが表示される- 何も表示されない
正解は「3. RecyclerView
のみが表示される」です。いくら"Floating"ActionButtonといえどもLinearLayout
の中で浮くことはできませんので、 RecyclerView
を画面いっぱいに敷き詰めてしまうと画面下のほうに追い出されてしまうということです。
こういうどうでもいいことにいちいち引っかかる私のような人が一人でも減ればいいと思って書いた。あるいは、運悪く引っかかってしまって泣きながらぐぐる人に見つけて欲しい。