這裏有幾個相關的帖子,但沒有一個是完全相同的情況/這些解決方案都沒有爲我工作。Android - RecyclerView開始在中間而不是頂部
我有一個RecyclerView,可以從Firebase中加載一些數據。我正在使用自定義適配器。問題是當視圖加載時,它會在RecyclerView的中間加載。然後我將不得不手動滾動到頂部。
我的佈局非常簡單:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/grey"
android:layout_marginBottom="50dp"
>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recycler_view_feed"
android:layout_marginTop="10dp"
>
</android.support.v7.widget.RecyclerView>
</LinearLayout>
從火力地堡我的自定義對象加載後,我設置了這樣的RecyclerView(這是一種方法是從onCreateView(這是一個片段)調用):
CompleteWorkoutRecyclerAdapter adapter = new CompleteWorkoutRecyclerAdapter(list, getContext(),
getActivity());
mRecyclerView.setAdapter(adapter);
mRecyclerView.setHasFixedSize(false);
linearLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, true);
mRecyclerView.setLayoutManager(linearLayoutManager);
我已經試過這些東西來解決這個問題,沒有運氣:
linearLayoutManager.scrollToPosition(0);
個
mRecyclerView.scrollToPosition(0);
和
android:focusableInTouchMode="true"
感謝您的閱讀。如果你們需要更多的代碼,我可以張貼任何你需要
什麼是列表的大小? –