0

My app contains tabs and a ScrollView. When I run it on a device, I can switch inbetween tabs by tapping and scroll up/down with no problem. However, the swiping horizontally (between tabs) doesn't seem to work. My guess is that there is a conflict between the ViewPager and the ScrollView, or there is a missing parameter. How can I solve it?

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                                 xmlns:tools="http://schemas.android.com/tools"
                                                 xmlns:app="http://schemas.android.com/apk/res-auto"
                                                 android:id="@+id/main_content"
                                                 android:layout_width="match_parent"
                                                 android:layout_height="match_parent"
                                                 android:fitsSystemWindows="true"
                                                 tools:context="com.example.user.myapplication.MainActivity">

    <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="@dimen/appbar_padding_top"
            android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/AppTheme.PopupOverlay"
                app:layout_scrollFlags="scroll|enterAlways">

        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:tabMode="scrollable"/>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

        <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                >
            <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/scrollView"
                    android:orientation="vertical"
                    android:background="@color/gray"
                    >
            </LinearLayout>
        </ScrollView>
    </android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer"/>

</android.support.v4.widget.DrawerLayout>
Evgeny
  • 107
  • 3
  • 17
  • Why `ViewPager` and `ScrollView` both are of `MatchParent` height ? – ADM Apr 27 '18 at 17:05
  • @ADM Are they supposed to be `wrap_content`? In any case that doesn't solve the problem – Evgeny Apr 27 '18 at 17:50
  • @Rockasaurus Your setup is messed up. `ViewPager` shall not be overridden by `ScrollView`. `ViewPager` supposed to be used to create scroll-able tabs. If you want to do the extra stuff, do it on `fragment` that you create using `FragmentPagerAdapter `. Currently `ScrollView` gets overlayed on `ViewPager` because both have same `height`. – Paresh P. Apr 27 '18 at 18:04
  • @Wizard Ok, I will look into it. Thank you for the reply! – Evgeny Apr 27 '18 at 18:21

0 Answers0