Home » Android » How to use ViewPager within NestedScrollView

How to use ViewPager within NestedScrollView

Posted by: admin November 1, 2017 Leave a comment

Questions:

In my application I want to use TabLayout and ViewPager inside NestedScrollView, but it doesn’t show ViewPager. I tried android:fillViewport="true" in NestedScrollView, but it didn’t help.

My XML codes:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:ignore="RtlHardcoded">

    <include
        android:id="@+id/celebrity_toolbar"
        layout="@layout/toolbar_search" />

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/celebrityDetail_scrollLay"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_below="@+id/celebrity_toolbar">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <RelativeLayout
                android:id="@+id/celebrity_suggestedYouLay"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/whiteMe"
                android:paddingBottom="@dimen/padding10"
                android:paddingLeft="@dimen/padding10"
                android:paddingRight="@dimen/padding10"
                android:paddingTop="@dimen/padding5"
                android:visibility="gone">

                <TextView
                    android:id="@+id/movieDetail_suggestedText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="@dimen/padding5"
                    android:fontFamily="sans-serif-light"
                    android:gravity="left"
                    android:text="@string/justTheTicketForYou"
                    android:textColor="@color/darkBlueGrey"
                    android:textSize="@dimen/font16" />

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/movieDetail_suggestedRecyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/movieDetail_suggestedText" />

            </RelativeLayout>
            <!--Space-->
            <android.support.v4.widget.Space
                android:id="@+id/celebrity_emptySpace"
                android:layout_width="match_parent"
                android:layout_height="@dimen/size15"
                android:layout_below="@+id/celebrity_suggestedYouLay"
                android:background="@color/whiteMe" />
            <!--Tab Layout-->
            <icom.app.test.Utils.Componenets.PlusTabLayout.TabLayoutPlus
                android:id="@+id/celebrity_tabLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/celebrity_emptySpace"
                android:background="@color/whiteMe"
                android:paddingBottom="@dimen/size3"
                android:paddingLeft="@dimen/size3"
                android:paddingRight="@dimen/size3"
                app:tabIndicatorColor="@color/colorAccent"
                app:tabSelectedTextColor="@color/colorAccent"
                app:tabTextAppearance="@style/allCapsTabLayout"
                app:tabTextColor="@color/black" />
            <!--Tab layout progress-->
            <ProgressBar
                android:id="@+id/celebrity_ProgressBar"
                android:layout_width="@dimen/size25"
                android:layout_height="@dimen/size25"
                android:layout_below="@+id/celebrity_emptySpace"
                android:layout_centerInParent="true"
                android:layout_gravity="center" />
            <!--ViewPager-->
            <icom.app.test.Utils.Componenets.DisableSwipeViewPager
                android:id="@+id/celebrity_viewPager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/celebrity_tabLayout" />

        </RelativeLayout>

    </android.support.v4.widget.NestedScrollView>

</RelativeLayout>

I added this code in java celebrityDetail_scrollLay.setFillViewport(true); but again it didn’t help.

How can I fix it and show ViewPager inside NestedScrollView ?

Answers: