Hi I have two question about scrolling behavior of android layout
Currently I have Following structure
CoordinatorLayout
- AppbarLayout
- Toolbar
- TabLayout
- ViewPager
For Toolbar, app:layout_scrollFlags="scroll|enterAlways" is set.
And inside ViewPager, There is RecyclerView1. and for it's item,
FrameLayout
- CardView
- Toolbar
- RecyclerView2
Q1.
When I scroll recyclerView2, Scrolling event doesn't seem to propagate to upper layers.
When I scroll recyclerView1's own item, Toolbar collapses and content inside ViewPager scrolls well.
But when I scroll recyclerView2's own item, toolbar doesn't collapses but content inside ViewPager scrolls.
why these thing happen? do i have to set recyclerView2's scroll 'disabled'?
how can i make my UI to have constant behavior? I want toolbar to collapse even if i scroll with RecyclerView2.
I'm using support library 24 and autoMesurement enabled for recyclerview.
Q2.
To tell the fact i am practicing to make live-score sports application.
So it goes like
Premier League(CardView as Item of RecyclerView)
Game1(RecyclerView)
Game2
Champions League(CardView as Item of RecyclerView)
Game1(RecyclerView)
Game2
I am kind of new to android so I wonder this kind of RecyclerView inside RecyclerView pattern is so common.
I implemented this way because i heard it's recommended to use recyclerView instead of ListView.
So I'm curios what other developers do when implementing (header-list)-list style in android.
Related
It's 2022, and I'm having the same issue with ViewPager2 that folks had with ViewPager (see NestedScrolling inside a Viewpager inside a BottomSheetDialog ) - 5 years ago.
Although I'm not using a BottomSheetDialogFragment, just a regular old bottom sheet (with a FragmentContainer).
ViewPager2 is a bit different in that it itself uses a horizontal RecyclerView. BottomSheetView.findScollingChild() sees this as the scrolling child!
So, the approach I took to solving this is:
added a page change listener to my ViewPager2 that gets the hosting
CoordinatorLayout, and calls requestLayout() on it after the page change.
copied the BottomSheetBehavior class that matches my current material components version (1.5) into my project, renamed it, and made findScrollingChild public.
subclassed that copy, and set the sub-class as the behavior on my sheet.
Why sub-class and not just change the findScrollingChild method directly? Well, this way it's relatively easy to update the copy of BottomSheetBehavior when we update our material components.
My implementation of findScrollingChild() in the sub-class checks specifically for a ViewPager2.
If it is, it gets child 0 of the ViewPager2 (the horizontal RecyclerView), and then uses recycler?.layoutManager?.findViewByPosition(pager.currentItem) as the view to then search for the scrolling child.
If the view is not a ViewPager2, it uses the same algorithm from the original findScrollingChild()
This basically works. I have a pager with 2 tabs, one containing a ScollView that has nested scrolling enabled, and one containing a RecyclerView. The bottom sheet expands as its scrolled, and then the contents of the nested child scroll down properly once the sheet is open.
The problem is if after the sheet has expanded if the finger gets lifted, then any attempt to scroll up causes the bottom sheet to close rather then scrolling up -- no matter how far it's been scrolled down. At least this is the case for the RecyclerView in the second tab, I don't have enough content in the first tab at the moment that it actually needs to scroll.
The sheet gets closed with the list still scrolled down several pages (or wherever you stopped scrolling). If however you scroll down -- even just a little bit -- scrolling up works again! And you can swipe a couple times and it will work - until it doesn't, and the sheet moves to the half expanded state.
I'm not sure where this behavior is coming from or how to resolve it. It doesn't happen when the bottom sheet has a direct RecyclerView (no ViewPager2 I'm the way).
I tried disabling swiping in the ViewPager2 thinking it might be interfering with touch events, but to no avail.
I have a MotionLayout which basically contains an image and a ViewPager. The ViewPager renders a fragment with a RecyclerView in it.
At first the image has normal size, when i drag up, the image reduces its size and the ViewPager (with the RecyclerView within it) expands.
The problem is that the MotionLayout keeps intercepting the scroll action, so if the RecyclerView is expanded, and the user scrolls down, the MotionLayout will expand the image, rather than letting the RecyclerView scroll.
What i would expect is that the MotionLayout will expand the top image only if the RecyclerView has reached the first element, in that case since the RecyclerView cannot scroll anymore, the scroll action would be managed by the MotionLayout.
I am aware that within MotionLayout I can set the attribute moveWhenScrollAtTop="true" to get that behaviour, but that only works if there is just a RecyclerView, but not if the RecyclerView is within a ViewPager.
Has anyone faced this issue?
if your xml file contains nested scrollview just add android:nestedScrollingEnabled="false"
Here is what I am trying to achieve:
Link to google's material design guide
In my case I have multiple cards in a scrollView, which contains a linear layout. I did not use a recycler view because the number of cards is always about the same (below 10). One of the cards contains two recyclerviews showing a list of for example comments. The problem is that I can't find a way to disable scrolling of the internal recyclerview without causing it to not scroll at all and show incomplete data.
Thanks for your help!
Use a NestedScrollView and put your RecyclerView inside it.
If you wish the RecyclerView to become a scrolling part of your NestedScrollView, set nested scrolling to false.
NestedScrollView nestedScrollView = findViewById(R.id.myNestedScrollView);
nestedScrollView.setNestedScrollingEnabled(false);
If you want an independent scroll you don't need to do anything since nested scrolling is set to true by default.
In my app I am using Activity & Fragment.Collapsing ToolBar is in Activity and RecyclerView is in Fragment.
I have attached two images.
* Before Scrolling
* After Scrolling the items are gone up.So created an empty space at the Bottom.
Here I need to stop the collapsing if the recyclerview has visible items at there. If items are more, scroll has to be enabled.How to do this? Please help.
Even I referred the below link. But there is no combination of Activity & Fragment Collapsing ToolBar scrolling.
How to disable scrolling of NestedScrollView&CollapsingToolbarLayout, for example when there is no more content below?
Create AppBar layout public in activity and in fragment according to recycle view count set expand like this
int itemCount=adapter.size();
if(itemCount>4){
((YourActivity)getActivity()).appBarLayout.setExpanded(true,true);
}else{
((YourActivity)getActivity()).appBarLayout.setExpanded(false,true);
}
adapter.size() refers to your recycleview adapter count
I made collapsible toolbar on Activity, but there is one problem.
Screen contains RecyclerView that has multiple layout items, and one of them is another RecyclerView that has horizontal scroll. When main recycler is scrolled, toolbar doesn't expand or collapse when scroll started on that nested recycler, but on other views it's working as it should.
To make it easier to understand: when I first touch screen on position where there is nested RecyclerView and try to scroll up and down, there is no collapsing or expanding of toolbar.
Any idea what might be causing that issue and how to fix it?
I only needed to set recyclerView.setNestedScrollingEnabled(false) for the nested RecyclerView to work.
Thanks to Reddit user in this thread:
Toolbar not collapsing with nested RecyclerView
For those who would like the same thing in Kotlin is:
recyclerView.isNestedScrollingEnabled = false
And for XML it is this property in RecyclerView but only for API 21 and higher:
android:nestedScrollingEnabled="false"