0
다음은 코드에 포함되어 있지만 내 스크롤 위치의 상태를 저장하고 복원하지 않습니다. 사용자가 전화를 돌릴 때 스크롤 위치를 저장하고 복원하려고합니다. recyclerview가 onOrientationChanged를 추가하고 그에 recyclerview 위치를 설정하여 활동에서GridLayoutManager를 사용하여 recyclerview의 상태 저장 및 복원
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRecyclerView = (RecyclerView) findViewById(R.id.rv_main_activity);
mRecyclerView.setHasFixedSize(true);
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
mRecyclerView.setLayoutManager(mGridLayoutManager = new GridLayoutManager(this, 3));
} else {
mRecyclerView.setLayoutManager(mGridLayoutManager = new GridLayoutManager(this, 5));
}
mMoviesAdapter = new MoviesAdapter(this, this);
mRecyclerView.setAdapter(mMoviesAdapter);
if (Build.VERSION.SDK_INT > 10) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
getSupportLoaderManager().initLoader(ID_MOVIE_LOADER, null, this);
MoviesSyncTask.syncMovies(this, "popular");
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(SCROLL_POSITION, mRecyclerView.getLayoutManager().onSaveInstanceState());
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
if (savedInstanceState != null) {
mListState = savedInstanceState.getParcelable(SCROLL_POSITION);
mRecyclerView.getLayoutManager().onRestoreInstanceState(mListState);
}
}
을 저장? – Vahalaru