0
コーディネーターレイアウトで視差ヘッダーを作りたいと思います。私は、coordinatorlayoutにrecyclerviewを入れました。できます。しかし、recyclerviewはすべてのデータをロードしますが、私はデータリストをページに分割します。最後の項目をスクロールするたびに、次のページをロードします。しかし、最初はすべてのデータが読み込まれます。CoordinatorLayoutでRecyclerviewが展開されないようにする方法
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<FrameLayout
android:id="@+id/bannerFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:id="@+id/nestedScrollView"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/productListFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
MainActivity.java
AppBarLayout appBarLayout = (AppBarLayout)findViewById(R.id.appbar);
appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
@Override
public void onStateChanged(AppBarLayout appBarLayout, State state) {
if(state == State.COLLAPSED){
Log.i("ScrollView", "COLLAPSED");
}
else {
Log.i("ScrollView", "UNCOLLAPSED");
}
}
});
BannerFragment bannerFragment = BannerFragment.newInstance();
ProductListFragment productListFragment = ProductListFragment.newInstance();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.addToBackStack("Banner");
ft.add(R.id.bannerFrame, bannerFragment, "Banner");
ft.commit();
ft = getSupportFragmentManager().beginTransaction();
ft.addToBackStack("ProductList");
ft.add(R.id.productListFrame, productListFragment, "ProductList");
ft.commit();
ProductListFragment.java
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
mAdapter = new MoviesAdapter(movieList);
GridLayoutManager mLayoutManager = new GridLayoutManager(getContext(), 1);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setHasFixedSize(true);
recyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener((GridLayoutManager)recyclerView.getLayoutManager()) {
@Override
public void onLoadMore(int current_page) {
if(current_page == 2){
prepareMovieData2();
}
}
});
recyclerView.setAdapter(mAdapter);
prepareMovieData();
}