Scroll both view pager and recycler view in single scroll

风格不统一 提交于 2019-12-05 06:18:39

问题


I'm developing app which has 4 tabs with view pagers. tab1 has scroll view and within the scroll view i have another tab layout with view pagers... When i full swipe tab1 i want recycler view within sub tab1 also to scroll when it reaches top.. currently i need to scroll seperately for scroll view and for recycler view.. Here is the Image of my app requirement...

Here is my xml for Main tab layout:

<LinearLayout 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:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

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

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

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

here is xml for Tab1:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 
    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">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

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

                    <com.daimajia.slider.library.SliderLayout
                        android:id="@+id/homeBannerSlider"
                        android:layout_width="match_parent"
                        android:layout_height="150dp"
                        app:indicator_visibility="visible"
                        app:pager_animation="Default"
                        app:pager_animation_span="400">

                        <com.daimajia.slider.library.Indicators.PagerIndicator
                            android:id="@+id/custom_indicator"
                            style="@style/AndroidImageSlider_Corner_Oval_Orange"
                            android:layout_alignParentBottom="true"
                            android:layout_centerHorizontal="true"
                            android:background="#00000000" />
                    </com.daimajia.slider.library.SliderLayout>
                </RelativeLayout>

                <android.support.v7.widget.CardView
                    android:layout_width="match_parent"
                    android:layout_height="30dp"
                    android:elevation="0dp"
                    app:cardCornerRadius="0dp"
                    app:cardElevation="0dp">

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

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentLeft="true"
                            android:layout_centerVertical="true"
                            android:layout_marginLeft="20dp"
                            android:text="Latest Results" />
                    </RelativeLayout>
                </android.support.v7.widget.CardView>


          <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:orientation="vertical">
                    <android.support.design.widget.TabLayout
                        android:id="@+id/home_Sub_TabLayout"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:tabTextAppearance="@style/MineCustomTabText"
                        app:tabSelectedTextColor="@color/colorPrimary"
                        app:tabIndicatorColor="@color/colorPrimary"
                        app:tabTextColor="#858585"
                        app:tabMode="fixed"
                        app:tabGravity="fill"/>
                    <android.support.v4.view.ViewPager
                        android:id="@+id/home_Sub_Viewpager"
                        android:layout_width="match_parent"
                        android:layout_height="400dp">
                    </android.support.v4.view.ViewPager>
                </LinearLayout>
            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>

code for subtab1 with recycler view:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
    android:id="@+id/trending_recycler_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>

</LinearLayout>

Pls suggest how i can achieve this...

来源:https://stackoverflow.com/questions/40467343/scroll-both-view-pager-and-recycler-view-in-single-scroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!