RecyclerView
高さが に設定されていますwrap_content
。今、私はそれに実装OnLoadMore
する必要がありますが、問題があります。私が使用した、
RecyclerView.OnScrollListener.onScrolled(RecyclerView recyclerView, int dx, int dy)
RecyclerView
しかし、スクロールしないため、呼び出されません。その高さはwrap_content
です。
<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
。onLoadMore
これを行う最善の方法は、最後のアイテムが表示されたときにイベントを呼び出すことだと思いRecyclerView
ます。アダプターのメソッドからこれを実行しようとしましonBindViewHolder
たが、すべてのページが完全に読み込まれました。
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();
}
}
}
onLoadMore
スクロールイベントを使わずに実装する別の方法は何ですか?
アップデート:
私のスクロールはスムーズRecyclerView
に動作します。android:layout_height:"wrap_content"
ScrollView
更新 2:
私の問題は、RecyclerView
身長がの場合wrap_content
、 のスクロール イベントを呼び出せRecyclerView
ないことです。そのため、リストの最後にいつRecyclerView
到達したかを確認し、そのOnLoadMore
方法でイベントを実装する別の方法が必要です。
アップデート 3
問題に書く前にxmlを単純化しました...実際のxmlでは、ViewPager
の代わりにRecyclerView
. そしてViewPager
、各タブにはRecyclerView
異なる内容の が含まれているという 4 つのタブがあります。
この上に、ViewPager
ユーザーに関する情報がいくつかあり、それらすべてを一緒にスクロールしたいと考えています。そこで、このヘッダーとViewPager
を aに入れScrollView
、の高さを に設定RecyclerView
しwrap_content
ます。
インスタグラムのプロフィールページからご覧いただけます。私はこのページがそのように機能することを望んでいます。
この情報をヘッダーに表示することはできません。この方法では、この情報をすべてのタブRecyclerView
のそれぞれに追加する必要があるためです。RecyclerView