同步两张垂直的Recyclerview卡以同时滑动

时间:2018-12-02 13:26:30

标签: android android-recyclerview

因此,我要做的是创建一张垂直的卡片列表,该卡片一旦位于屏幕中心,就会将其图像设置为背景(例如-poweramp's vertical swipe of album changes background as same!),速度如此之快,以至于即使在缓慢滑动时也可以看到色彩融合并涌现出新艺术。 这正是我要以垂直方式进行的操作,除了它必须具有与Poweramp一样的平滑滑动效果。

到目前为止,我所做的是实现两个recyclerview的(一个在另一个之后,也欢迎其他建议),其中top recyclerview(1)显示获取的数据(即,从实例处的服务器获取所有图像和数据) ),背景recyclerview(2)会显示与顶部recyclerview具有相同动画的图像(BLURRED!)。

现在是踢球者,(2)正在根据(1)更改背景图像,但是在(1)上完全滑动后,(2)就会更改。

代码如下: JAVA

    mRecyclerView = (RecyclerView) findViewById(R.id.homecardlist1);
    mRecyclerViewBck = (RecyclerView) findViewById(R.id.homecardlistBck);

     mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setItemViewCacheSize(10);
    mRecyclerView.setDrawingCacheEnabled(true);
    mRecyclerView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);

     mRecyclerViewBck.setLayoutManager(layoutManagerBck);
    mRecyclerViewBck.setHasFixedSize(true);
    mRecyclerViewBck.setItemViewCacheSize(10);
    mRecyclerViewBck.setDrawingCacheEnabled(true);
    mRecyclerViewBck.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);


     RecyclerView.OnScrollListener scrollListener = new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);

            int f2 =layoutManager.findFirstCompletelyVisibleItemPosition();
            if(f1[0]>=0) {
                pos = f1[0];
                 mRecyclerViewBck.smoothScrollToPosition(pos);

            }

        }
    };

    mRecyclerViewBck.addOnScrollListener(scrollListener);
    mRecyclerView.addOnScrollListener(scrollListener);

XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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/tools"
    android:id="@+id/activity_feed_polls"
    android:background="#212121"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1">


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

        <android.support.v7.widget.RecyclerView
            android:id="@+id/homecardlistBck"
            android:visibility="visible"
            android:layout_gravity="center"
            android:nestedScrollingEnabled="false"
            android:clipToPadding="false"
            android:layout_marginTop="@dimen/_60sdp"
            android:layout_marginBottom="@dimen/_40sdp"
            android:layout_width="match_parent"

            android:requiresFadingEdge="vertical"
            android:fadingEdgeLength="250dp"
            android:fadingEdge="vertical"
            android:fadeScrollbars="true"
            android:layout_height="match_parent"/>


    <android.support.v4.widget.SwipeRefreshLayout

        android:elevation="30dp"
        android:id="@+id/SwipeRefreshLayout"
        android:layout_marginTop="@dimen/_60sdp"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="@dimen/_40sdp"
        android:clipToPadding="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/homecardlist1"
            android:visibility="visible"
            android:layout_gravity="center"
            android:nestedScrollingEnabled="false"
            android:clipToPadding="false"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>

高度赞赏实现此目的的任何其他方法。

0 个答案:

没有答案