0
coordinatorlayout으로 시차 헤더를 만들고 싶습니다. 코디네이터 레이아웃에 리사이클 뷰를 추가했습니다. 그것은 작동합니다. 그러나 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();
}