我已經使用Android應用程序庫使用工具欄和TabLayout製作應用程序。
實際上有2個選項卡,都帶有2個RecyclerView,當滾動時它會自動摺疊工具欄。當RecyclerView適合屏幕時,不要摺疊工具欄
我的問題是:我可以禁用工具欄摺疊時,RecyclerView有幾個項目,完全適合屏幕(如在選項卡2)?
我見過很多像CheeseSquare這樣的例子,由Google員工製作,問題仍然存在:即使RecyclerView只有1個項目,工具欄仍然保持滾動狀態。
我想我可以找出是否RecyclerView的第一項是顯示在屏幕上,如果是禁用的工具欄崩潰。前者很容易實現,後者呢?
這是我的佈局:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/glucosio_pink"
app:tabSelectedTextColor="@android:color/white"
app:tabIndicatorColor="@color/glucosio_accent"
app:tabTextColor="#80ffffff"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/main_fab"
android:layout_margin="16dp"
android:onClick="onFabClicked"
app:backgroundTint="@color/glucosio_accent"
android:src="@drawable/ic_add_black_24dp"
android:layout_gravity="bottom|right"
/>
</android.support.design.widget.CoordinatorLayout>
你能告訴我你是怎麼創造這個GIF? –
Hi @PratikButani!我在網上找到了gif(https://mzgreen.github.io/2015/06/23/How-to-hideshow-Toolbar-when-list-is-scrolling(part3)/)。順便說一句,你可以使用像https://gifs.com/這樣的服務從YouTube視頻創建一個gif。 –
用你的鏈接傾訴給那個人:)願他會幫助你。謝謝:) https://twitter.com/pratik13butani/status/644355243174526976 –