我想用RecyclerView和Toolbar創建簡單的CoordinatorLayout,但與標準解決方案的不同之處在於工具欄應該位於底部,並且在RecyclerView滾動到底部時應該消失。CoordinatorLayout底部的工具欄
因此,我創建簡單的佈局:
當然<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recycler_view"/>
</android.support.design.widget.CoordinatorLayout>
中的工具欄在頂部而不是底部。我該如何解決這個問題?
不幸的是,這是不可能用你的解決方案,因爲我得到ClassCastException異常,在XML第二件事應該是RecyclerView。 – ThirdMartian
哦,如果我記得好了CoordinatorLayout是FrameLayout的一個子類,你可以在xml塊中交換元素,而不會產生副作用。請參閱我的編輯! – fiipi
哦,我錯了,這是暫時的錯誤,現在工具欄是在底部,我試圖找到滾動隱藏/顯示的解決方案。我不想使用底部導航欄,因爲工具欄上的項目應該打開新的活動,而不是在容器中更換新的片段。我的意思是,已經爲底部導航欄創建的庫對於我的解決方案來說太大了,但也許我將不得不使用它們。 – ThirdMartian