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"
I have one RecyclerView inside Bottom Sheet and I don't want recyclerview to be scrollable inside it. But here I am facing a problem that Bottom Sheet expand and Collapse swipe property interfere with Recyclerview scroll and nothing is happening when I swipe. Please help me to solve this issue.
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.
What is the difference between ScrollView and NestedScrollView? Both of them, extend FrameLayout. I want to know in depth pros and cons of both of them.
NestedScrollView as the name suggests is used when there is a need for a scrolling view inside another scrolling view. Normally this would be difficult to accomplish since the system would be unable to decide which view to scroll.
This is where NestedScrollView comes in.
In addition to the nested scrolling NestedScrollView added one major functionality, which could even make it interesting outside of nested contexts: It has build in support for OnScrollChangeListener. Adding a OnScrollChangeListener to the original ScrollView below API 23 required subclassing ScrollView or messing around with the ViewTreeObserver of the ScrollView which often means even more work than subclassing. With NestedScrollView it can be done using the build-in setter.
Other than the advantages listed in the answers given, one more advantage of NestedScrollView over ScrollView is its compatibility with CoordinatorLayout. The ScrollView does not cooperate with the CoordinatorLayout. You have to use NestedScrollView to get "scroll off-screen" behaviour for the toolbar.
Toolbar will not collapse with Scrollview as child of CoordinatorLayout
NestedScrollView
NestedScrollView is just like ScrollView, but it supports acting as
both a nested scrolling parent and child on both new and old versions
of Android. Nested scrolling is enabled by default.
https://developer.android.com/reference/android/support/v4/widget/NestedScrollView.html
ScrollView
Layout container for a view hierarchy that can be scrolled by the
user, allowing it to be larger than the physical display. A
ScrollView is a FrameLayout, meaning you should place one child in it
containing the entire contents to scroll; this child may itself be a
layout manager with a complex hierarchy of objects
https://developer.android.com/reference/android/widget/ScrollView.html
NestedScrollView is just like ScrollView, but in NestedScrollView we can put other scrolling views as child of it, e.g. RecyclerView.
But if we put RecyclerView inside NestedScrollView, RecyclerView's smooth scrolling is disturbed. So to bring back smooth scrolling there's trick:
ViewCompat.setNestedScrollingEnabled(recyclerView, false);
put above line after setting adapter for recyclerView.
I think one Benefit of using Nested Scroll view is that the cooridinator layout
only listens for nested scroll events. So if for ex. you want the toolbar to scroll down when you scroll you content of activity, it will only scroll down when you are using nested scroll view in your layout. If you use a normal scroll view in your layout, the toolbar wont scroll when the user scrolls the content.
<androidx.core.widget.NestedScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
// your Layout xml code
</androidx.core.widget.NestedScrollView>
I have an activity with CollapsingToolbarLayout for parallax effect(From Android Design Library) and FrameLayout where i set Fragment.
Fragments layout contains NestedScrollView.
Everything is working well except one moment. In NestedScrollView I have a horizontal RecyclerView with StaggerGridLayoutManager and when i scroll vertically from that recyclerview - parallax not starting. When i scroll from any other place of screen it works.
Seems it's problem with layout_behavior tag or loosing focus of NestedScrollView.
Does any one faced this problem ? Some ideas ?
Fuh! Got a solution! Disabling nested scroll on RecyclerView solved the problem.
recyclerView.setNestedScrollingEnabled(false);