RecyclerView's height not adjusted when the AppBarLayout is expanded - android

The code for initializing the RecyclerView
private void initRecyclerView() {
layoutManager = new GridLayoutManager(this, spanCount);
mRecyclerRV.setLayoutManager(layoutManager);
mRecyclerRV.addItemDecoration(new GridSpacingItemDecoration(spanCount, (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, spaceInDp, getResources().getDisplayMetrics()) + 1), false));
mRecyclerRV.setNestedScrollingEnabled(false);
mRecyclerRV.setAdapter(mAdapter);
mRecyclerRV.addOnScrollListener(new RecyclerView.OnScrollListener() {
#Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (!recyclerView.canScrollVertically(-1)
&& RecyclerView.SCROLL_STATE_SETTLING == newState
&& mScrollVerticalDirection
&& mIsAppBarCollapsed) {
mAppBarLayout.setExpanded(true);
}
}
#Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
mScrollVerticalDirection = (dy < 0);
}
});
mRecyclerRV.postDelayed(new Runnable() {
#Override
public void run() {
RecyclerView.ViewHolder holder = mRecyclerRV.findViewHolderForAdapterPosition(1);
if (null != holder) {
holder.itemView.performClick();
}
}
}, 1000);
}
The layout file is here, and uses CoordinatorLayout
<?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:id="#+id/activity_local_album_coordinator"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="#color/colorPageBg">
<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_local_album_appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border_bottom_bg"
android:theme="#style/Wemeet.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/activity_local_album_collapsing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/dp2"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<android.support.v7.widget.Toolbar
android:id="#+id/local_album_toolbar"
style="#style/WemeetTitlebar"
android:layout_marginStart="-10dp"
android:titleTextColor="#color/colorText33"
app:layout_scrollFlags="scroll"
android:theme="#style/Wemeet.Toolbar">
<TextView
android:id="#+id/comm_toolbar_title"
style="#style/WemeetTitlebar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:text="相机胶卷"
android:gravity="center"
android:singleLine="true" />
</android.support.v7.widget.Toolbar>
<LinearLayout
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_marginTop="#dimen/dp48"
android:layout_height="350dp"
app:layout_scrollFlags="scroll">
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#color/colorDivider"
android:id="#+id/fg_top_border" />
<com.weiguan.wemeet.basecomm.ui.widget.WemeetVideoView
android:visibility="gone"
android:layout_gravity="center"
android:id="#+id/activity_local_album_preview_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</com.weiguan.wemeet.basecomm.ui.widget.WemeetVideoView>
<ImageView
android:id="#+id/activity_local_album_preview_iv"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter" />
</LinearLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/activity_local_album_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
</android.support.design.widget.CoordinatorLayout>
When the AppBarLayout is collapsed the RecyclerView scroll happens correctly.
But when the AppBarLayout is expanded, the height of the RecyclerView does not adjust and the scrolling appears abnormal

No ways to get it. But resize the recycler view when the app bar is expand or gonna collapse.

Related

How to add pull to refresh in Coordinator layout

I have an AppBar and RecyclerView in CoordiantorLayout. SwipeToRefresh has to be fullscreen but RecyclerView not scrolling down then.
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="128dp"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
How to add fullscreen pull to refresh in Coordinator layout without a library.
You can disable swipe refresh layout when AppBar isn't fully expanded and enable it if it is fully expanded.
vAppBar.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { _, verticalOffset ->
vSwipeRefresh.isEnabled = verticalOffset == 0
})
I add swipetorefresh top level like answer above. And I fix my scroll up issue with code below. Thanks to mohammadReza :)
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener(){
#Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
int topRowVerticalPosition =
(recyclerView == null || recyclerView.getChildCount() == 0) ? 0 : recyclerView.getChildAt(0).getTop();
swipeRefreshLayout.setEnabled(topRowVerticalPosition >= 0);
}
#Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
});
try to set SwipeRefreshLayout as root parent like this :
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout 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="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="128dp" />
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

Recyclerview scrolling doesn't work in fragment that in nested scroll view

First off all : I worked before with recycler views and on scroll Listener and everything was great but this first time to use coordinator layout and use fragment in nested scroll view so i think the problem related to design
here's my summary on scroll code
categoryRecyclerView?.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
Log.e("scrolling","scroll")
if (dy > 0) {
Log.e("scrolling","vertical")
So when i scroll i didn't see ("scrolling","vertical") in my logcat but i only see ("scrolling","scroll") just one time no matter i scroll or not
here's my activity 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_height="match_parent"
android:layout_width="match_parent"
android:background="#color/layoutBackground">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<FrameLayout
android:padding="8dp"
android:id="#+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="bottom"
android:background="#color/colorPrimary"
android:padding="8dp"
app:layout_behavior="#string/hide_bottom_view_on_scroll_behavior"
app:itemIconTint="#drawable/navigation_item_selector"
app:itemTextColor="#android:color/white"
app:menu="#menu/navigation_menu" />
</android.support.design.widget.CoordinatorLayout>
and here's my fragment xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/layoutBackground"
tools:context=".fragments.AllItemsFragment">
<android.support.v7.widget.RecyclerView
android:id="#+id/categoryRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="#layout/entertainment_recycler_view_item" />
<ProgressBar
android:id="#+id/loadingCategoryList"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
in onActivtyCreated in fragment i set
scrollView.isNestedScrollingEnabled = false
and in init recyclerview code i set recyclerview to
categoryRecyclerView?.isNestedScrollingEnabled = false
categoryRecyclerView?.setHasFixedSize(false);
Set
categoryRecyclerView?.isNestedScrollingEnabled = true
And instead of using recyclerview.addOnScrollListener(), use nestedScrollView.setOnScrollChangeListener().
nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
#Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX,
int oldScrollY) {
LinearLayoutManager layoutManager = (LinearLayoutManager) questionRecyclerView.getLayoutManager();
if (layoutManager != null) {
int visibleItemCount = layoutManager.getChildCount();
int totalItemCount = layoutManager.getItemCount();
int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
if (!questionAdapter.isLoading()) {
if (visibleItemCount +firstVisibleItemPosition >= totalItemCount
&& firstVisibleItemPosition >= 0
&& totalItemCount >= PAGE_SIZE) {
// loadMore();
}
}
}
}
}});

Hide and show custom view on scroll inside a SwipeRefreshLayout

I'm trying to implement hide/show SearchView on scroll feature inside a SwipeRefreshLayout.
I want to show SearchView when user scroll to the bottom and hide - when scroll to top.
Also i want to keep swipe refresh behaviour.
Tried many examples, but haven't seen close results.
My xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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">
<include layout="#layout/loading_bar"/>
<include layout="#layout/network_error"/>
<include layout="#layout/empty_materials_coinlist"/>
<RelativeLayout
android:id="#+id/coinlist_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/coinlist_item_bg">
<RelativeLayout
android:id="#+id/custom_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="exitUntilCollapsed">
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="toolbar_title"
android:textColor="#color/toolbar_text_color"
android:textSize="18sp"
android:typeface="sans"
android:layout_gravity="center" />
</RelativeLayout>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/custom_toolbar">
<android.widget.SearchView
android:id="#+id/sv_coin"
android:layout_width="match_parent"
android:layout_height="40dp"
android:iconifiedByDefault="false"
app:layout_scrollFlags="scroll|enterAlways|snap"/>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/currenciesRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/coinlist_item_bg"
android:scrollbars="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
Try this
myRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
#Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
#Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy > 0) {
//check for scroll down
int itemPosition = linearLayoutManager.findFirstCompletelyVisibleItemPosition();
if(itemPosition==list.size()){// your last item your recyclerview
// hide your SearchView here
}
} else {
//check for scroll up
int itemPosition = linearLayoutManager.findLastCompletelyVisibleItemPosition();
if(itemPosition==0){
// show your SearchView here
}
}
}
});

How to get an Item of Recyclerview when scroll stopped?

I have a Recyclerview inside Scrollview, I want to store item details of Recyclerview where scroll stopped.
I have a xml like,
<ScrollView
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="match_parent"
android:background="#color/White">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/tile_view_pager"
android:layout_width="match_parent"
android:layout_height="200dp"
android:visibility="gone"
android:layout_marginRight="2dp"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/news_feed_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</RelativeLayout>
I have added ScrollListener for recyclerview. But As I'm using parent Scrollview for the activity, recyclerview's ScrollListener is not getting called.
I tried changing parent scrollview to NestedScrollView then recyclerview is scrolling as a one item at once but i want scroll to be freely. Like scrolling our contacts.
Issue : When I scroll, Parent ScrollView getting scrolled and I don't have any control on my recyclerview. So It's difficult to figure out which item of recyclerview is visible once scroll stopped.
Basically I want to code without changing my XML.
I want to store item details of Recyclerview where scroll stopped.
When scroll stops, scroll state transitions into idle state. However, idle state is the state before and after scroll. Therefore you are looking for a transition into idle state after settling state.
Do it like this:
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
boolean scrolled;
int[] displayedPositions;
#Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_SETTLING) {
scrolled = true;
} else if (newState == RecyclerView.SCROLL_STATE_IDLE && scrolled) {
scrolled = false;
int[] into = new int[//number of spans];
displayedPositions = ((StaggeredGridLayoutManager) recyclerView.getLayoutManager()).findFirstCompletelyVisibleItemPositions(into)
}
}
}
private int overallXScrol = 0;
//...
mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
#Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
overallXScroll = overallXScroll + dx;
Log.i("check","overall->" + overallXScroll);
}
});
try NestedScrollView instead scrollview like below
<android.support.v4.widget.NestedScrollView
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="match_parent"
android:background="#color/White">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/tile_view_pager"
android:layout_width="match_parent"
android:layout_height="200dp"
android:visibility="gone"
android:layout_marginRight="2dp"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/news_feed_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</RelativeLayout>
I found the solution. Just we need to change layout. I'm using CoordinatorLayout as a parent view. And Now I'm able to use onScrollListener of recyclerview.
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/White">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="#+id/tile_view_pager"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginEnd="2dp"
android:visibility="gone"/>
</LinearLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/news_feed_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>

Endless load more recyclerview inside nested scroll android

I have Recyclerview inside the nestedscrollview and I want to scroll the nestedscrollview to the buttom display loading and load more list to recyclerview.
Here is my xml.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="kh.com.iknow.endless.MainActivity">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Filter"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Sort"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="vertical" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
you can do it in two ways :
1- adding header to recyclerview
2- using setOnScrollChangeListener method of NestedScrolview
I prefer the second way :
NestedScrollView nestedSV = (NestedScrollView) findViewById(R.id.nested_sync_scrollview);
if (nestedSV != null) {
nestedSV.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
#Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
String TAG = "nested_sync";
if (scrollY > oldScrollY) {
Log.i(TAG, "Scroll DOWN");
}
if (scrollY < oldScrollY) {
Log.i(TAG, "Scroll UP");
}
if (scrollY == 0) {
Log.i(TAG, "TOP SCROLL");
}
if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
Log.i(TAG, "BOTTOM SCROLL");
if (!isRecyclerViewWaitingtoLaadData) //check for scroll down
{
if (!loadedAllItems) {
showUnSentData();
}
}
}
}
});
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/off_white_bg"
android:orientation="vertical">
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="2dp"
android:fitsSystemWindows="true">
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScrollViewId"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical"
app:layout_scrollFlags="scroll|enterAlways">
<LinearLayout
android:id="#+id/permiumLAyout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/divider"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:focusableInTouchMode="true"
android:gravity="center"
android:orientation="vertical"
android:visibility="visible">
<!-- List view -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/btn_br_color"
android:padding="3dp">
<TextView
android:id="#+id/primiumGameNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_marginLeft="15dp"
android:gravity="center"
android:maxLines="4"
android:text="Primium Games"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/row_text_color"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view_primiumGameList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="false"
android:nestedScrollingEnabled="false"
android:paddingBottom="3dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="3dp" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</FrameLayout>
</LinearLayout>
I Noted one issue putting my RecyclerView inside the NestedScrollView. I realized that scrolling the content of my RecyclerView slacked.Getting issue in scrolling. And one main issue load more data getting issue for load data inside NestedScrollView.
Solution: use load more event like this
mRecAdapter = new RecyclerAdapter(recylerView,
primiumgameDetailsArrayList, getActivity(), cost);
recylerView.setAdapter(mRecAdapter);
//set load more listener for the RecyclerView adapter
mRecAdapter.setOnLoadMoreListener(new OnLoadMoreListener() {
#Override
public void onLoadMore () {
**mRecyclerView.setNestedScrollingEnabled(false);**
if (reqCountStatus.equalsIgnoreCase("true")) {
primiumgameDetailsArrayList.add(null);
mRecAdapter.notifyItemInserted(primiumgameDetailsArrayList.size() - 1);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
primiumgameDetailsArrayList.remove(primiumgameDetailsArrayList.size() - 1);
mRecAdapter.notifyItemRemoved(primiumgameDetailsArrayList.size());
int index = primiumgameDetailsArrayList.size();
primiumGameloadData(mRecyclerView, index);
}
}, 5000);
} else {
mRecyclerView.setNestedScrollingEnabled(false);
Toast.makeText(getActivity().getApplicationContext(),
"Loading data completed", Toast.LENGTH_SHORT).show();
}
}
});
Note:I had to disable the scroll functionality of my RecyclerView with this method mRecyclerView.setNestedScrollingEnabled(false); and enable when load more request for data mRecyclerView.setNestedScrollingEnabled(true)

Categories

Resources