Как использовать viewpager внутри вложенногоScrollView с верхним представлением viewpager

Я не могу прокручивать вложенныйScrollView из-за viewpager. Итак, позвольте мне объяснить вот дизайн макета, который я хочу создать:

введите описание изображения здесь

Внутри NestedScrollView есть FrameLayout и пейджер с вкладками. Viewpager загружает три фрагмента с бесконечным recylerview (Pagination).

Вот XML-код макета:

<android.support.design.widget.CoordinatorLayout 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context="com.plowns.droidapp.activites.HomeActivity">

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

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </RelativeLayout>


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

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

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_marginTop="50dp"
    android:background="@color/colorPrimary" />


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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:background="@color/trans">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="260dp">

                <android.support.v7.widget.CardView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="55dp"
                    app:cardCornerRadius="5dp">

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">

                        <ImageView
                            android:id="@+id/txt_edit_icon"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentRight="true"
                            android:src="@drawable/ic_mode_edit"
                            android:tint="@color/blue_plowns" />

                        <TextView
                            android:id="@+id/txt_child_name"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="50dp"
                            android:ellipsize="end"
                            android:gravity="center_vertical"
                            android:minHeight="5dp"
                            android:text="Satwinder Singh"
                            android:textAppearance="?android:attr/textAppearanceListItemSmall"
                            android:textColor="@android:color/black"
                            android:textSize="18sp"
                            android:textStyle="bold" />

                        <LinearLayout
                            android:id="@+id/ll_points_class"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/txt_child_name"
                            android:layout_centerHorizontal="true"
                            android:orientation="horizontal">

                            <TextView
                                android:id="@+id/txt_child_points"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_gravity="center_horizontal"
                                android:text="10038"
                                android:textAppearance="?android:attr/textAppearanceListItemSmall"
                                android:textColor="@color/gray"
                                android:textSize="14sp" />

                            <View
                                android:id="@+id/point_class_sapretor"
                                android:layout_width="1dp"
                                android:layout_height="10dp"
                                android:layout_gravity="center"
                                android:layout_marginLeft="5dp"
                                android:background="@color/gray" />

                            <TextView
                                android:id="@+id/txt_child_class"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginLeft="5dp"
                                android:text="Collage"
                                android:textAppearance="?android:attr/textAppearanceListItemSmall"
                                android:textColor="@color/gray"
                                android:textSize="13sp" />

                        </LinearLayout>

                        <LinearLayout
                            android:id="@+id/ll_title"
                            android:layout_width="fill_parent"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/ll_points_class"
                            android:layout_centerHorizontal="true"
                            android:orientation="horizontal"
                            android:visibility="gone">

                            <TextView
                                android:id="@+id/txt_title"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_gravity="center_horizontal"
                                android:ellipsize="end"
                                android:maxLines="1"
                                android:singleLine="true"
                                android:text=""
                                android:textAppearance="?android:attr/textAppearanceListItemSmall"
                                android:textColor="@android:color/white"
                                android:textSize="14sp" />

                        </LinearLayout>


                        <android.support.v7.widget.CardView
                            android:id="@+id/card_badge"
                            android:layout_width="100dp"
                            android:layout_height="20dp"
                            android:layout_below="@+id/ll_title"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="5dp"
                            android:backgroundTint="@color/yellow_plowns"
                            app:cardCornerRadius="5dp">

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_gravity="center"
                                android:text="BADGE WALL"
                                android:textColor="@color/white"
                                android:textSize="12sp"
                                android:textStyle="bold" />

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

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="50dp"
                            android:layout_below="@+id/card_badge"
                            android:layout_centerHorizontal="true"
                            android:layout_marginLeft="10dp"
                            android:layout_marginRight="10dp"
                            android:layout_marginTop="5dp"
                            android:baselineAligned="false"
                            android:gravity="center"
                            android:orientation="horizontal"
                            android:weightSum="3">

                            <RelativeLayout
                                android:id="@+id/rl_upload"
                                android:layout_width="fill_parent"
                                android:layout_height="fill_parent"
                                android:layout_weight="1"
                                android:paddingTop="5dp">

                                <TextView
                                    android:id="@+id/txt_upload_count"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_centerHorizontal="true"
                                    android:text="13"
                                    android:textAppearance="?android:attr/textAppearanceListItemSmall"
                                    android:textColor="@color/black"
                                    android:textSize="15sp"
                                    android:textStyle="bold" />

                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@+id/txt_upload_count"
                                    android:layout_centerHorizontal="true"
                                    android:layout_marginTop="5dp"
                                    android:text="@string/profile_title_uploads"
                                    android:textAppearance="?android:attr/textAppearanceListItemSmall"
                                    android:textColor="@color/gray"
                                    android:textSize="13sp" />

                                <View
                                    android:layout_width="1dp"
                                    android:layout_height="40dp"
                                    android:layout_alignParentRight="true"
                                    android:layout_centerVertical="true"
                                    android:background="@color/gray" />


                            </RelativeLayout>

                            <RelativeLayout
                                android:id="@+id/rl_followers"
                                android:layout_width="fill_parent"
                                android:layout_height="fill_parent"
                                android:layout_weight="1"
                                android:paddingTop="5dp">

                                <TextView
                                    android:id="@+id/txt_follower_count"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_centerHorizontal="true"
                                    android:text="13"
                                    android:textAppearance="?android:attr/textAppearanceListItemSmall"
                                    android:textColor="@color/black"
                                    android:textSize="15sp"
                                    android:textStyle="bold" />

                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@+id/txt_follower_count"
                                    android:layout_centerHorizontal="true"
                                    android:layout_marginTop="5dp"
                                    android:text="@string/profile_title_followers"
                                    android:textAppearance="?android:attr/textAppearanceListItemSmall"
                                    android:textColor="@color/gray"
                                    android:textSize="13sp" />

                                <View
                                    android:layout_width="1dp"
                                    android:layout_height="40dp"
                                    android:layout_alignParentRight="true"
                                    android:layout_centerVertical="true"
                                    android:background="@color/gray" />

                            </RelativeLayout>

                            <LinearLayout
                                android:id="@+id/ll_following"
                                android:layout_width="fill_parent"
                                android:layout_height="fill_parent"
                                android:layout_weight="1"
                                android:gravity="center"
                                android:orientation="vertical">

                                <TextView
                                    android:id="@+id/txt_following_count"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:text="47"
                                    android:textAppearance="?android:attr/textAppearanceListItemSmall"
                                    android:textColor="@color/black"
                                    android:textSize="15sp"
                                    android:textStyle="bold" />

                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_marginTop="5dp"
                                    android:text="@string/profile_title_following"
                                    android:textAppearance="?android:attr/textAppearanceListItemSmall"
                                    android:textColor="@color/gray"
                                    android:textSize="13sp" />


                            </LinearLayout>

                        </LinearLayout>

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="25dp"
                            android:layout_alignParentBottom="true"
                            android:background="@color/colorPrimary"
                            android:orientation="horizontal">

                            <LinearLayout
                                android:id="@+id/ll_share"
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_weight="0.5"
                                android:gravity="center"
                                android:orientation="horizontal">

                                <TextView
                                    android:id="@+id/txt_share_icon"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:gravity="center"
                                    android:text="&#xf0c0;"
                                    android:textColor="@color/pink"
                                    android:textSize="15sp" />

                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_marginLeft="10dp"
                                    android:gravity="center"
                                    android:text="Invite friends"
                                    android:textAppearance="?android:attr/textAppearanceListItemSmall"
                                    android:textColor="@android:color/white"
                                    android:textSize="14sp" />

                            </LinearLayout>

                            <LinearLayout
                                android:id="@+id/ll_switch_child"
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_weight="0.5"
                                android:gravity="center"
                                android:orientation="horizontal">

                                <ImageView
                                    android:id="@+id/txt_switch_child_icon"
                                    android:layout_width="22dp"
                                    android:layout_height="22dp"
                                    android:background="@drawable/ic_switch"
                                    android:textAllCaps="false"
                                    android:textColor="@color/white" />

                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_marginLeft="10dp"
                                    android:gravity="center"
                                    android:text="Switch profile"
                                    android:textAppearance="?android:attr/textAppearanceListItemSmall"
                                    android:textColor="@android:color/white"
                                    android:textSize="14sp" />

                            </LinearLayout>

                        </LinearLayout>

                    </RelativeLayout>

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

            </FrameLayout>

            <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/img_child_profile"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_gravity="top|center_horizontal"
                android:layout_marginTop="5dp"
                android:src="@drawable/blank_profile"
                app:border_color="@color/colorPrimary"
                app:border_width="2dp" />

        </FrameLayout>



        <android.support.v7.widget.CardView
            android:id="@+id/card_bottom"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="10dp"
            app:cardCornerRadius="5dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <android.support.design.widget.TabLayout
                    android:id="@+id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/white"
                    app:tabGravity="fill"
                    app:tabIndicatorColor="@color/colorPrimary"
                    app:tabIndicatorHeight="0dp"
                    app:tabMode="fixed"
                    app:tabSelectedTextColor="@color/white"
                    app:tabTextColor="@color/white" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/gray" />

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

            </LinearLayout>

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

    </LinearLayout>

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

Now when i scroll outside of viewpager nothing happened (view not scroll). And on viewpager scroll only recyclerview scroll. But I want to scroll the whole view on outside frame layout scroll and on recylerview also.

Что я пробовал:

1) Установите фиксированную высоту для Viewpager (700dp). Результат: прокрутка в Framelayout работала плавно, но прокрутка в Recyclerview работала неправильно и плавно. Мне нужно прокручивать много раз, чтобы прокрутить.

2) Установите Framelayout и Tablayout внутри AppBarLayout. Результат: прокрутка вверх работала гладко, но при прокрутке вниз Recylerview (Viewpager) сначала полностью прокручивался Appbarlayout, а затем прокручивался контент Recyclerview, который находился за Appbarlayout. Поэтому мне нужно прокрутить весь список, чтобы увидеть первое содержимое, это плохой опыт.

3.) Создал пользовательский Viewpager, как предлагается здесь, например введите здесь описание ссылки Результат: То же, что и в первом случае:

4) Отключено Нажмите на Viewpager и используйте пользовательский Viewpager. Результат: Плавная прокрутка всего представления, но из-за отключения сенсорного экрана на Viewpager я не могу разбить на страницы Recyclerview, что означает необходимость проверять каждый тип касания и определять конец прокрутки для загрузки следующих данных в Recyclerview. Я не хочу это делать.

Итак, вот моя проблема. Пожалуйста, если у кого-то есть решение или что-то подобное, пожалуйста, помогите. Заранее спасибо.


person Satwinder Singh    schedule 19.12.2017    source источник


Ответы (1)


Итак, я, наконец, решил эту проблему, просто создав Custom ViewPager, как указано здесь: Custom ViewPager, который вычисляет высоту ViewPager и setNestedScrollingEnable(false) на RecyclerView внутри Viewpager. Установив NestedScrollingEnalbe = false, Recyclerview устанавливает прокрутку родительского NestedScrollView. Итак, Parent NestedScrollView работает внутри Viewpager.

person Satwinder Singh    schedule 20.12.2017
comment
как создать пользовательский адаптер пейджера просмотра - person Mohammad Sommakia; 04.10.2018