Android Scroll Problems - CoordinatorLayout + CollapsingToolBarLayout + View Pager + Recycler View

时间:2017-09-03 00:09:51

标签: android android-viewpager android-coordinatorlayout vertical-scrolling

让我的recyclerview滚动时遇到问题。我正在尝试实现视差图像效果,所以我找到了this教程并采用了它。之后,我注意到我的viewpager中的回收站视图不再滚动了。

我已经查看了一些解决方案:我找到this,但似乎没有任何效果。

这是我的XML:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/rel_layout_size"
        android:background="@android:color/white"
        android:orientation="horizontal"
        android:focusable="true"
        >

        <ImageView
            android:id="@+id/search_icon"
            android:layout_width="@dimen/icons_size"
            android:layout_height="@dimen/icons_size"
            android:src="@drawable/search"
            android:layout_alignParentEnd="true"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:layout_marginRight="15dp"
            android:layout_marginLeft="10dp"
            />

        <ImageView
            android:id="@+id/like_icon"
            android:layout_width="@dimen/icons_size"
            android:layout_height="@dimen/icons_size"
            android:src="@drawable/like"
            android:layout_toStartOf="@id/search_icon"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            />

    </RelativeLayout>
    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="@android:color/white"
    >

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:theme="@style/AppTheme.LightActionBar"
        app:contentScrim="@android:color/white"
        android:fitsSystemWindows="true"
    >

        <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/htab_collapse_toolbar"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:fitsSystemWindows="true"
                app:contentScrim="@android:color/white"
                app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
                app:titleEnabled="false">



                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/home"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerCrop"
                    app:layout_collapseMode="parallax"
                    app:layout_collapseParallaxMultiplier="0.75"
                    />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:alpha="0.1"
                    android:background="@android:color/white"
                    android:fitsSystemWindows="true"/>



                <android.support.v7.widget.Toolbar
                    android:layout_width="match_parent"
                    android:layout_height="20dp"
                    android:layout_gravity="top"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>



                <android.support.design.widget.TabLayout
                    android:id="@+id/tabLayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:background="@android:color/white"
                    app:tabIndicatorColor="@android:color/black"
                    app:tabSelectedTextColor="@android:color/black"
                    app:tabTextColor="@android:color/darker_gray"/>

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

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

        <xyz.santeri.wvp.WrappingViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
        />

    </android.support.design.widget.CoordinatorLayout>
</LinearLayout>

示例片段XML如下所示:

<android.support.v4.widget.NestedScrollView
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:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_gravity="fill_vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerViewArtworks"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

1 个答案:

答案 0 :(得分:0)

我后来找到了解决方案。原来,RelativeLayout修复了它。这可以帮助某人

  <RelativeLayout
    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" >

<RelativeLayout
    android:id="@+id/search_bar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/rel_layout_size"
    android:background="@android:color/white"
    android:orientation="horizontal"
    android:layout_alignParentTop="true"
    android:focusable="true"
    >

    <ImageView
        android:id="@+id/search_icon"
        android:layout_width="@dimen/icons_size"
        android:layout_height="@dimen/icons_size"
        android:src="@drawable/search"
        android:layout_alignParentEnd="true"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:layout_marginRight="15dp"
        android:layout_marginLeft="10dp"
        />

    <ImageView
        android:id="@+id/like_icon"
        android:layout_width="@dimen/icons_size"
        android:layout_height="@dimen/icons_size"
        android:src="@drawable/like"
        android:layout_toStartOf="@id/search_icon"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        />

</RelativeLayout>

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_below="@+id/search_bar"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="@android:color/white"
    >

 <android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:theme="@style/AppTheme.LightActionBar"
    app:contentScrim="@android:color/white"
    android:fitsSystemWindows="true"
    >
    <!--android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"-->



    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/htab_collapse_toolbar"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:fitsSystemWindows="true"
        app:contentScrim="@android:color/white"
        app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
        app:titleEnabled="false">



        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/home"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.75"
            />

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:alpha="0.1"
            android:background="@android:color/white"
            android:fitsSystemWindows="true"/>



        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="20dp"
            android:layout_gravity="top"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
        <!--android:layout_height="?attr/actionBarSize"-->


        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@android:color/white"
            app:tabIndicatorColor="@android:color/black"
            app:tabSelectedTextColor="@android:color/black"
            app:tabTextColor="@android:color/darker_gray"
            android:fillViewport="false" />

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/darker_gray"/>

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

        <!--<xyz.santeri.wvp.WrappingViewPager-->
        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
        />
    </android.support.design.widget.CoordinatorLayout>