【问题标题】:RecyclerView is scrolling to the bottom of the view after loading items from Firebase从 Firebase 加载项目后,RecyclerView 滚动到视图底部
【发布时间】:2017-03-18 20:10:58
【问题描述】:

如何让视图保持在列表的开头?

我尝试过scrollTo(0,0),但它似乎不起作用。

编辑: 我的recyclerview imp..

newsFeedView.setHasFixedSize(false);
newsFeedView.setLayoutManager(
    new LinearLayoutManager(this.getActivity(), LinearLayoutManager.VERTICAL, true));
FirebaseRecyclerAdapter<NewsFeed, NewsFeedHolder> mAdapter;
mAdapter = new FirebaseRecyclerAdapter<NewsFeed, NewsFeedHolder>(NewsFeed.class,
    R.layout.item_newsfeed, NewsFeedHolder.class,
    database.child("posts").orderByChild("timeCreated")) {...}

<android.support.v7.widget.RecyclerView
  android:id="@+id/detail_comments_view"
  android:layout_width="0dp"
  android:layout_height="295dp"
  android:layout_marginLeft="8dp"
  android:layout_marginRight="8dp"
  android:layout_marginTop="8dp"
  android:clickable="true"
  android:windowSoftInputMode="adjustResize"
  app:layout_constraintLeft_toLeftOf="parent"
  app:layout_constraintRight_toRightOf="parent"
  app:layout_constraintTop_toBottomOf="@+id/details_cv"
  android:layout_marginBottom="0dp"
  app:layout_constraintBottom_toTopOf="@+id/comment_test_button"
  />

如果您需要更多,请告诉我

【问题讨论】:

  • 考虑添加一些代码,以便我们更好地帮助您...
  • 你确定你没有添加一些让recyclerview自动滚动的代码吗?
  • 是的,我很确定我对我的房车的所有呼叫都与此无关

标签: android firebase firebase-realtime-database android-recyclerview


【解决方案1】:

我不得不改变

new LinearLayoutManager(this.getActivity(), LinearLayoutManager.VERTICAL, false));

并添加

.setReverseLayout(true);
.setStackFromEnd(true);

【讨论】:

    猜你喜欢
    • 2017-04-09
    • 1970-01-01
    • 2017-12-21
    • 2019-12-07
    • 2016-06-16
    • 2020-09-18
    • 2015-11-05
    • 2016-12-12
    相关资源
    最近更新 更多