user3875913
user3875913

Reputation: 252

RecyclerView is scrolling to the bottom of the view after loading items from Firebase

How do I get the view to remain at the beginning of the list?

I have tried scrollTo(0,0) but it did not seem to work.

EDIT: my 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"
  />

let me know if you need more

Upvotes: 1

Views: 1971

Answers (1)

user3875913
user3875913

Reputation: 252

I had to change

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

and add

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

Upvotes: 1

Related Questions