[英]Recycler view Inside NestedScrollView with CoordinatorLayout
[英]Endless recycler view inside coordinatorLayout
我们如何在协调器布局中实现无尽的回收器视图? 下面是我的布局。
<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();
}
}
}
}
});
任何帮助表示赞赏。 谢谢。
可以在 RecyclerView 上设置 OnScrollListener 以在该 RecyclerView 上发生滚动事件时接收消息。
这是一篇非常好的文章如何实现这一点....l墨水
目前,您正在指示LayoutManager
反转其布局(这就是第三个/布尔参数的用途)。 因此,顺序颠倒了。
你会想要改变:
final LinearLayoutManager mLayoutManager =
new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, true);
到:
final LinearLayoutManager mLayoutManager =
new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
这与仅调用相同:
final LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.