无限右滚动回收站视图

时间:2016-06-15 12:39:40

标签: android android-recyclerview

我有一个奇怪的问题,当我在水平回收视图中向右滚动时,滚动是无限的,而呈现的项目是循环呈现。

那就是我有15个项目,当显示第15个项目时向右滚动显示第一个项目等等...

这可能会变得很酷,但这不是我的意图,当试图向左滚动它也不会从第一个项目回到第15个

当我将回收器视图宽度从“match_parent”更改为带有权重的线性布局内的视图时,就会发生这种情况:

    <LinearLayout
            android:layout_width="match_parent"
            android:weightSum="1"
            android:layout_height="wrap_content"
            android:layout_below="@id/appTrailersTV"
            android:paddingTop="10dp"
            android:paddingBottom="10dp">
            <!--android:background="@color/antique_white"-->

            <ImageView
                android:layout_weight="0.1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:src="@drawable/ic_keyboard_arrow_right_black_24dp"/>

            <android.support.v7.widget.RecyclerView
                android:layout_weight="0.8"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:id="@+id/appTraliersRV"
                android:layout_marginRight="3dp"
                android:layout_marginLeft="3dp"/>

            <ImageView
                android:layout_weight="0.1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:src="@drawable/ic_keyboard_arrow_right_black_24dp"/>

        </LinearLayout>

这是回收者视图的代码:

        myAppsRV.setAdapter(myAppsdapter);
        LinearLayoutManager myAppsllm = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
        myAppsRV.setLayoutManager(myAppsllm);

我真正想要的是滚动到最后一个项目结束

当跟踪滚动侦听器的日志时,它显示可见视图的索引显示正确的索引1-14,当达到15时,其切换回1:

appTraliersRV.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            Log.i(Utils.TAG, "appTrailersMoreTV index: " + (((LinearLayoutManager) recyclerView.getLayoutManager()).findLastVisibleItemPosition() +1));
            if ((((LinearLayoutManager) recyclerView.getLayoutManager()).findLastVisibleItemPosition() +1)== AppResources.trailersVideos.size()) {
                appTrailersMoreTV.setVisibility(View.VISIBLE);
            }
            else
            {
                appTrailersMoreTV.setVisibility(View.GONE);
            }
        }
    });

0 个答案:

没有答案
相关问题