我们如何在 co-ordinator 布局中实现无尽的 recyclerview?下面是我的布局。
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ParentTownMaterialTheme.AppBarOverlay">
// Inside linear layout child views are there
<LinearLayout
android:id="@+id/linear_scroll_enter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/response_lv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/linear_scroll_enter"
android:background="@android:color/white"
android:clipToPadding="false"
android:divider="@android:color/transparent"
android:paddingBottom="6dp"
android:paddingTop="6dp"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
无休止的 recyclerview 在这里工作,但顺序相反。如 :
item 10
item 9
item 8
item 7
item 6
----------
LOAD MORE
----------
item 5
item 4
item 3
item 2
item 1
它应该是这样的:
item 1
item 2
item 3
item 4
item 5
-----------
LOAD MORE
-----------
item 6
item 7
item 8
item 9
item 10
这是java代码:
response_lv.setHasFixedSize(false);
final LinearLayoutManager mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, true);
response_lv.setLayoutManager(mLayoutManager);
response_lv.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
response_lv.setItemAnimator(new DefaultItemAnimator());
response_lv.setAdapter(profileFragmentRecyclerAdapter);
response_lv.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) {
if ((mLayoutManager.getChildCount() + mLayoutManager.findFirstVisibleItemPosition()) >= mLayoutManager.getItemCount()) {
Log.d("TAG", "End of list");
totalItemCount = mLayoutManager.getItemCount();
lastVisibleItem = mLayoutManager.findLastVisibleItemPosition();
if (!isLoading && totalItemCount <= (lastVisibleItem + visibleThreshold)) {
isLoading = true;
current_page++;
setLoadingView();
new ProfileAsyncTask().execute();
}
}
}
}
});
任何帮助表示赞赏。谢谢。