我把它的高度设为。现在我需要实现RecyclerView,但有一个问题。
我用过,

RecyclerView.OnScrollListener.onScrolled(RecyclerView recyclerView, int dx, int dy)

但是它没有被调用,因为我的wrap_content没有滚动。它的高度是OnLoadMore
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/root_rtl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">

    <include
        android:id="@+id/tool_bar"
        layout="@layout/toolbar" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/tool_bar">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:context="com.yarima.msn.Activities.ProfileActivity">

            <FrameLayout
                 android:id="@+id/FRAGMENT_PLACEHOLDER"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:background="@color/white">

                 <!-- Some Content That I want to scroll with recyclerview -->
            </FrameLayout>

            <android.support.v7.widget.RecyclerView
                 android:id="@+id/recyclerview_posts"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:scrollbars="vertical"
                 android:bellow="@id/FRAGMENT_PLACEHOLDER"/>
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>

所以我需要使用另一种方法来加载更多的页面到RecyclerView
我认为最好的方法是当wrap_content的最后一项变为可见时调用RecyclerView事件。我已经尝试在适配器中的onLoadMore方法中执行此操作,但所有页面都已加载。
if(getItemCount()-position == 1 && onLoadMoreListener != null){
    if (recyclerView != null) {
        visibleItemCount = recyclerView.getChildCount();
        totalItemCount = recyclerView.getLayoutManager().getItemCount();
        firstVisibleItem = ((LinearLayoutManager)recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
        if (loading) {
            if (totalItemCount > previousTotal) {
                loading = false;
                previousTotal = totalItemCount;
            }
        }
        if (!loading && (totalItemCount - visibleItemCount)
                <= (firstVisibleItem + visibleThreshold)) {
            loading = true;
            onLoadMoreListener.onLoadMore();
        }
    }
}

不使用滚动事件实现RecyclerView的替代方法是什么?
更新:
onBindViewHolderonLoadMore完美配合,我的RecyclerView滚动顺畅。
更新2:
我的问题是当您的android:layout_height:"wrap_content"高度为ScrollView时,无法调用RecyclerView的滚动事件。所以我需要另一种方法来找出我的wrap_content何时到达其列表的末尾,并以这种方式实现RecyclerView事件。
更新3
我在写有疑问的XML之前简化了它…在真正的XML中,存在RecyclerView而不是OnLoadMore。我有4个标签,ViewPager每个标签包含不同内容的RecyclerView
上面的ViewPager我有一些关于用户的信息,我想把它们一起滚动。所以我把这个标题和RecyclerView放在一个ViewPager中,并将ViewPager的高度设置为ScrollView
你可以看看Instagram的个人资料页面。我想这一页像那样工作。
无法在RecyclerView的标题中显示此信息,因为这样,我应该在每个选项卡的每个wrap_content中添加此信息。

最佳答案

编辑
可以在ScrollView中查找滚动事件
https://developer.android.com/reference/android/view/View.html#onScrollChanged(int,整数,整数,整数)

07-24 09:46
查看更多