Android three levels recyclerview - android

I've been puzzling now on this quite a while.....
In my activity I have a recyclerview with a row adapter (vertical). In each row I have a recyclerview with a panel adapter (horizontal). In each panel I have a recyclerview with an item adapter (vertical).
Everything works fine but when I try to scroll the items the rows are scrolling, not the items.
What I want is that the items will scroll, unless there are not enough items in a panel to scroll, (like in panel B3) then the rows should be scrolling. In case there are enough items in a panel to scroll and I reach top or bottom of the items in a panel, then the rows should start scrolling.
Can anyone point me in the right direction?

Make sure your layout is inside NestedScrollView:
<android.support.v4.widget.NestedScrollView
android:id="#+id/nScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<FrameLayout ...>
<android.support.v7.widget.RecyclerView
.........
</android.support.v7.widget.RecyclerView>
</FrameLayout >
</android.support.v4.widget.NestedScrollView>

try:
mRecyclerView.setNestedScrollingEnabled(true);

Related

RecyclerView smoothScrollToPosition(lastItem) scrolls to bottom where last item is partially visible

Im working on chat type screen where new text msg item is added in list and recyclerView is scrolled to last position of the list but the last item is partially visible, and does not scroll till end of bottom when the keyboard is open. I have added
android:layout_width="match_parent"
android:gravity="top"
android:layout_gravity="fill_vertical"
android:windowSoftInputMode="adjustResize"
android:clipToPadding="false"
android:layout_height="match_parent"
app:layout_constrainedHeight="true"
app:layout_scrollFlags="scroll|enterAlways"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_marginBottom="#dimen/margin_5"
to the recycler view.
I have also tried to use recyclerView.layoutMangaer.smoothScrollToPosition, ScrollBy() method, and also used some 300 msec delay to scroll.
Nothing worked.
Will appreciate some help. Thanks.

Recyclerview inside NestedScrollView - Scroll to bottom

I have a RecyclerView inside a NestedScrollView:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="#dimen/_100sdp">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view_chat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="#dimen/_100sdp"
android:layout_marginLeft="#dimen/_30sdp"
android:layout_marginRight="#dimen/_30sdp"
android:background="#color/bright_grey"
></android.support.v7.widget.RecyclerView>
</android.support.v4.widget.NestedScrollView>
My RecyclerView is being filled with items in onCreate()
On a device you would see the first item of the RecyclerView on the very top und would have to scroll down the NestedScrollView in order to see the last item.
Since my items are chat message sorted by the time sent I need the NestedScrollView to be scrolled all the way down so users would see the latest chat message first without having to scroll in the first place.
Any ideas on this?
Given that your RecyclerView is the only child of your NestedScrollView, you would be better off removing the NestedScrollView altogether, and instead applying the fixed height to the RecyclerView. Something like this:
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view_chat"
android:layout_width="match_parent"
android:layout_height="#dimen/_100sdp"
android:layout_marginLeft="#dimen/_30sdp"
android:layout_marginRight="#dimen/_30sdp"
android:background="#color/bright_grey" />
Doing this allows you to have the RecyclerView itself manage scrolling, rather than the parent scroll view. And that allows you to leverage a property of LinearLayoutManager to achieve what you want.
Reverse layout -- setting this will "invert" your list; the first item in your adapter will appear at the bottom of the list, and the default scroll position of the RecyclerView will be to scroll all the way to the bottom.
https://developer.android.com/reference/android/support/v7/widget/LinearLayoutManager.html#setReverseLayout(boolean)
LinearLayoutManager lm = new LinearLayoutManager(this);
lm.setReverseLayout(true);
If you have the same issue and want to keep the NestedScrollView.
It will work like this.
Handler(Looper.getMainLooper()).postDelayed({
binding.nestedScrollView.smoothScrollTo(
0,
binding.recyclerview.measuredHeight,
500
)
// binding.nestedScrollView.scrollTo(0, binding.recyclerview.measuredHeight)
// binding.nestedScrollView.smoothScrollTo(0, binding.recyclerview.measuredHeight)
}, 50L)
For me, it didn't work without delay.

Move layout up when layout above shrinks in height

Hi I have a fragment with two RecyclerViews in it, one above the other.
The first is a list of items for the user to take an action on and the second is where the items will be populated once the action is taken. So when an item is removed from the top list it is added to the bottom list.
The issue I am having is when I remove an item from the top RecyclerView all the remaining items in the top RecyclerView move up to fill in the space left by the removed item, but this leaves a gap between the top and bottom RecyclerViews.
How can I move the bottom recyclerview up to fill in the gap created once an item is removed from the top RecyclerView
Here is my layout xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_alignParentTop="true"
android:id="#+id/pending_tasks"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:layout_below="#id/pending_tasks"
android:id="#+id/completed_tasks"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
I have tried calling invalidate() on the bottom RecyclerView but that has not worked. Any help would be appreciated, thanks!
It's impossible to update layout size once it's been displayed on the screen. If you modify the content of your RecyclerView you can't just simply refresh the layout to shrink it.
I would suggest using single RecyclerView and storing lower bound of the first list in some variable. Then simply update it accordingly to modifications in your first list.
Another solution which may help you:
Change Relative layout width and height dynamically

Nested Recycler View Scrolling Issue

I have used Recycler View Inside Nested Scroll View(which is within CoordinatorLayout):
<android.support.v4.widget.NestedScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/sections_recycler_view_linearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
Within the adapter of above recycler I have added Child Recycler Views programatically using setNestedScrollingEnabled as false.
My Issue is:
When I am scrolling the child recycler, as soon as its scroll is completed the parent recycler scrolls to top, as if I am setting its adapter again. I have not added any code to notify adapter or to scroll to top-most recycler item or to set adapter again. I could not figure out the reason for this strange behavior.
Any help would be highly appreciated.. !!!
Add to your parent Recycler View:
android:descendantFocusability="blocksDescendants"
I was display progress bar in child recycler views until I receive data from server. And once I get data I was populating it. I had used staggered Adapter for child recyclers with row count 2 and hence after data got populated my parent recyler's height was changing.
I used setHasFixedSize(false) for parent recycler view as its height was changing and I have not seen the issue again till now.
Easy,
Add
android:fillViewport="true"
to your NestedScrollview and you will be good to go.

How to stop the scroll of particular view at position for RecyclerView android?

I have recycler view.At position 0 ,I had made header and from position 1 rest of the items will come.This is my layout
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_content"
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.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="2dp">
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/recyler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="2dp"
android:background="#color/listview"
/>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
I want when i scroll my recycler view , and when half the header is scrolled up,the remaining header get stick at top ,and other items of recycler view scroll.And after certain point the sticky part of header also moves up.How to achive it.
To make a sticky header you need to provide ItemDecorator to RecyclerView
If You want to do something like this .
The library is currently not maintained. You need to make some changes by yourself.
How ItemDecorator works:-
ItemDecorator gives you power to draw something over RecyclerView. In your case you want to put a sticky header for some time and after next header item you want to replace the new header with earlier one.
So Using ItemDecorator you can draw same header view over RecyclerView top position which look like to user as a header item is get fixed on top and when next header item comes it will replace with new one.
Hope It will helps you.

Categories

Resources