RecyclerView LinearLayout管理器始终在横向模式下返回-1-findLastCompletelyVisibleItemPosition() [英] RecyclerView LinearLayout manager always returns -1 in landscape mode - findLastCompletelyVisibleItemPosition()

查看:144
本文介绍了RecyclerView LinearLayout管理器始终在横向模式下返回-1-findLastCompletelyVisibleItemPosition()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用findLastCompletelyVisibleItemPosition()确定RecyclerView中的最后一个可见项目.

I'm using findLastCompletelyVisibleItemPosition() to determine the last visible item in my RecyclerView.

这是我如何设置布局的代码段:

Here is a code snippet of how I'm setting up my layout:

    mRecyclerView.setHasFixedSize(true);
    LinearLayoutManager mLayoutManager = new LinearLayoutManager(getContext());
    mRecyclerView.setLayoutManager(mLayoutManager);

布局XML:

<android.support.v4.widget.SwipeRefreshLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/message_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:paddingBottom="@dimen/footer_progress_bar"
        android:paddingTop="16dp"
        android:scrollbars="vertical" />

    <ProgressBar
        android:id="@+id/progress_bar"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:visibility="gone" />

    <ProgressBar
        android:id="@+id/footer_progress_bar"
        android:layout_width="@dimen/footer_progress_bar"
        android:layout_height="@dimen/footer_progress_bar"
        android:layout_gravity="center|bottom"
        android:visibility="gone" />

</FrameLayout>
</android.support.v4.widget.SwipeRefreshLayout>

在纵向模式下,这可以正常工作,并且始终返回正确的位置.

In portrait mode, this works fine and always returns the right position.

但是在横向模式下,返回的位置始终为-1.

However in landscape mode, the position returned is always -1.

我的问题是:

有人知道为什么会这样吗?

Does anyone know why this happens?

如何覆盖它以返回正确的位置?

How I can override this to return the right position?

或者有人可以推荐另一种解决方案来使景观中的最后一个项目正确定位吗?

Or can anyone recommend another solution to get the right position of the last item in landscape?

推荐答案

您看到的"-1"是RecyclerView.NO_POSITION返回码,表明存在 在横向模式下在RecyclerView中没有完全可见的位置. 完全可见"是指整个 视图,包括所有装饰及其边距(垂直方向的上/下边距和左/右 对于水平方向)是可见的.您可能会看到所有数据,但单个像素可能会偷偷溜走 观点.看看findLastCompletelyVisibleItemPosition()及其 调用findOneVisibleChild()

The "-1" that you are seeing is the RecyclerView.NO_POSITION return code indicating that there is no completely visible position in your RecyclerView in landscape mode. "Completely visible" means that the entire view including any decorations and its margins (top/bottom margins for vertical orientation and left/right for horizontal orientations) is visible. You may see all of your data, but a single pixel could be sneaking off out of view. Take a look at findLastCompletelyVisibleItemPosition() and its invocation of findOneVisibleChild() here.

再次检查您在RecyclerView中的可见位置是否具有100%的可见性,如上所述.在开发人员中显示利润 模式等.如果您确认至少有一个完全可见的位置,则还有其他更神秘的事情发生.

Double check that you have a 100% visible position in your RecyclerView as outlined above. Show margins in developer mode, etc. Something else more mysterious is going on if you verify that there is at least one completely visible position.

这篇关于RecyclerView LinearLayout管理器始终在横向模式下返回-1-findLastCompletelyVisibleItemPosition()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆