Recently, I used Android Design Support Library and I have the following code for my collapsing toolbar.
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/media_detail_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
>
<include
layout="@layout/layout_card"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<android.support.v7.widget.Toolbar
android:id="@+id/media_detail_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin"
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<android.support.design.widget.TabLayout
android:id="@+id/media_detail_tabs"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@color/blue_2"
app:tabMode="scrollable"
/>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
I have two fragments for the View Pager. One is NestedScrollView and the other is Recycler View. My issue is the NestedScrollView, here's the code below.
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
My issue is that when you scroll the view up, as soon as your finger moves a bit on the side, it triggers the horizontal scroll for the view pager. Could you please help me to avoid that ? When we scroll up and down, the view pager shouldn't be triggered. It works well in my recycler view fragment. Thanks.
As a container for a specific interaction with one or more child views. By specifying Behaviors for child views of a CoordinatorLayout you can provide many different interactions within a single parent and those views can also interact with one another.
The ViewPager is populated with fragments taking up space way beyond the screen (vertically). Still, nothing on the screen is scrollable.
NestedScrollView is just like ScrollView , but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.
I tried same layout with the latest version of these libraries
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
and it works well as expected, that is:
if the gesture is mainly vertical scroll (even diagonal) NestedScrollView triggers the scroll, otherwise if the gesture is mainly horizontal swipe (even with a minimal vertical gap) ViewPager triggers the swipe. To solve upgrade your libraries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With