我正在尝试为类似于WhatsApp的工具栏和TabLayout实现滚动效果。以下应该是功能:
AppBarLayout不应自行滚动,即,如果按住并尝试滚动工具栏和TabLayout,则它们不应滚动。
如果RecyclerView中没有足够的项目(包含在添加到ViewPager的片段中),则工具栏和TabLayout不应滚动。
TabLayout也应始终可见。
以下是活动布局。
<?xml version="1.0" encoding="utf-8"?>
<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/container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbarlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:background="@color/search_layover_bg">
<RelativeLayout
android:id="@+id/toolbar_container"
android:layout_width="match_parent"
app:layout_scrollFlags="scroll|enterAlways|snap"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary" />
<com.miguelcatalan.materialsearchview.MaterialSearchView
android:id="@+id/search"
android:inputType="textNoSuggestions|textUri"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
<com.gigamole.navigationtabstrip.NavigationTabStrip
android:id="@+id/tab”
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#BE2625"
app:nts_color="#ffffff"
app:nts_size="14sp"
app:nts_weight="3dp"
app:nts_factor="2"
app:nts_titles="@array/titles_tab”
app:nts_type="line"
app:nts_gravity="bottom"
app:nts_typeface="fonts/typeface.otf"
app:nts_corners_radius="0dp"
app:nts_animation_duration=“200"
app:nts_active_color="#ffffff"
app:nts_inactive_color="#60151c"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/vp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.robertlevonyan.views.customfloatingactionbutton.FloatingActionButton
android:id="@+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSizes="normal"
app:fabElevation="4dp"
app:fabColor=“#cccccc”
android:layout_gravity="bottom|end"
android:layout_marginRight="15dp"
android:layout_marginBottom="15dp"
app:fabIcon="@drawable/mail_icon"
app:fabIconColor="#ffffff"/>
</android.support.design.widget.CoordinatorLayout>
</android.support.design.widget.CoordinatorLayout>