我已经使用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 –