我试图制作一个具有Play商店/ WhatsApp的滚动效果(折叠栏?)的工具栏:当列表向上滚动时,工具栏隐藏,而TabLayout保持可见,然后向下滚动列表时,工具栏应在与ListView相同的位置滚动。
编辑:向上滚动时,工具栏会留一个空白: https://imgur.com/w4S0KiX
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.AppBarLayout
android:elevation="0dp"
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:fitsSystemWindows="true"
>
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="50dp"
app:layout_behavior="com.github.godness84.
appbarsnapbehavior.AppBarSnapBehavior"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:titleEnabled="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:orientation="vertical">
<include layout="@layout/toolbar_home"/>
</LinearLayout>
</android.support.design.widget.CollapsingToolbarLayout>
<LinearLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/colorPrimary"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
app:tabMode="scrollable"
android:layout_width="match_parent"
android:layout_height="50dp"
app:tabIndicatorColor="@color/colorPrimaryDark"
app:tabSelectedTextColor="#fff"
app:tabTextColor="@color/colorPrimaryDark">
<android.support.design.widget.TabItem
android:id="@+id/tabItemProdotti"
android:layout_height="wrap_content"
android:text="Prodotti"
android:layout_width="wrap_content" />
<android.support.design.widget.TabItem
android:id="@+id/tabItemCantieri"
android:layout_height="wrap_content"
android:text="Cantieri"
android:layout_width="wrap_content"/>
<android.support.design.widget.TabItem
android:id="@+id/tabClienti"
android:layout_height="wrap_content"
android:text="Clienti"
android:layout_width="wrap_content"/>
<android.support.design.widget.TabItem
android:id="@+id/tabItemImpostazioni"
android:text="Impostazioni"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<android.support.design.widget.TabItem
android:id="@+id/tabItemCredits"
android:layout_height="wrap_content"
android:text="Credits"
android:layout_width="wrap_content"/>
</android.support.design.widget.TabLayout>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
app:layout_behavior="com.github.godness84.
appbarsnapbehavior.ScrollingViewBehavior"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<android.support.v7.widget.Toolbar android:id="@+id/toolbarHome"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
app:titleTextColor="@color/white"
app:title="@string/app_name">
</android.support.v7.widget.Toolbar>