Android Recyclerview in ScrollView - android

I know it is not a good approach, but I have a layout with similar structure:
ScrollView
RelativeLayout (with TabLayout,textViews, ImageViews etc)
RecyclerView
RelativeLayout (with textViews, ImageViews etc)
The recyclerView part is dynamic, so it may have 1 TextView with ImageView, but it can have max. 4-5 lines of elements.
This is working fine, but when there are more items in recyclerView, then that section starts to scroll.
That's what I want to disable.
My RecyclerView part:
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
I added to the RecyclerView this line:
android:nestedScrollingEnabled="false"
So now the scrolling is disabled for that section, but now I don't see all items in RecyclerView.
How can I disable scrolling and keep the full height to see all the content there?

Related

RecyclerView inside NestedScrollview not scrolling smoothly

When I'm scrolling down, the items above the RecyclerView does not scroll unless I start touching from the layout above, and it only scrolls down when I have reached the end of the RecyclerView.
<NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout>
<Some other items.../>
</LinearLayout>
<RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</NestedScrollView>
Note:
I actually use a fixed size for the RecyclerView, setting it via the code below:
float height_recyclerview = (ScreenUtil.getHeight(context) - (height_banner + height_bottom_navigation + height_create_post));
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int) height_recyclerview);
rv.setLayoutParams(layoutParams);
Why do I use fixed size if it works smoothly with wrap_content?
I will be displaying possibly thousands of items that may have
images, which will hurt performance if it does not actually do
recycling because of the issue that the RecyclerView is inside the
NestedScrollView
I have implemented an EndlessRecyclerViewScrollListener which has an
issue that it keeps loading more data from server continuously if
implemented with a RecyclerView that is within whatever scrollable
view, or if it is in a scrollable view, but does not have a fixed
height, even if you are not scrolling down.
I have tried the following:
set nested scrolling to false on the recycler view
try using scroll view instead of nested scroll view
a bunch of other code related to layouts and scrolling behaviors that others suggested which didn't work for me because I'm implementing it in a much more complicated layout and the fact that I use EndlessRecyclerViewScrollListener
What I want to fix?
I want to make the page scroll like a single page, not as a separate scrollable view.
Note that my recycler view has a fixed height that takes the entire screen's space meaning that its height is actually fit assuming that the linear layout above is not visible anymore if the user has scrolled down.
The ideal scenario is to make the scrollview scroll down first, to make the recycler view take the entire screen, so that the recyclerview will scroll however the user wants to.
Then the linearlayout above which should not be visible anymore if the recycler view has taken up all the space of the screen, should only show up if the recycler view has reached the top/first item, if the user keeps scrolling back up.
Read this.
Add app:layout_behavior="#string/appbar_scrolling_view_behavior" to your recycler xml.
<android.support.v7.widget.RecyclerView
android:id="#+id/conversation"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
NestedScrollView Smooth Scrolling
recyclerView.isNestedScrollingEnabled = true
Do this programmatically
<androidx.core.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="0dp"
android:fillViewport="true"
...

Android Layout :- NestedScrollView + RecyclerView ----- Scrollable

In my application I have a three textview which I want to be scroll-able and then below that I want to place a recyclerView. Then after I want that I can scroll these three textview separately and when scrolling the recyclerView the whole layout scrolls so that the textview are scrolled up and recyclerView items gets displayed. I have tried a variour options but failed.
One way through which I am able to achieve this is:-
<ScrollView
<RelativeLayout
NestedScrollView
TextView1
TextView2
TextView3
</NestedScrollView>
<RecyclerView
</RecyclerView>
</RelativeLayout>
</ScrollView>
But while using this layout if recyclerView has less items (say 50-60 ) then it works well otherwise the application hangs and have to force close application.
After so many different tries I think when I place recyclerView inside ScrollView (or NestedScrollView) then such behavior occurs.
Please help me with layout setup

ScrollView not scrolling which has ListView inside (listview is scrolling)

I have a ListView inside ScrollView, the ListView works fine (it scrolls) but the ScrollView is not scrolling
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
</LinearLayout>
I want the full page to scroll (The textview should also scroll)
TextView
ListView
item1
item2
.
.
The full page must scroll along with the textview!
This will never work because your listView is effectively a scrollView, so you have a scrollView within a scrollView. Is the textView of fixed size or can it be a large amount of text? I would consider some redesign here as this is not a very good way to design a UI.
If the textView is big which means you only see a small bit of the list then you should be able to scroll by touching the textView only, but i would make the scrollView the Parent and remove the first LinearLayout, it is not needed
Instead of ListView switch to RecyclerView and inside your MainActivity.java in onCreate() do this recyclerView.setNestedScrollingEnabled(false);
You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.
The TextView class also takes care of its own scrolling, so does not require a ScrollView, but using the two together is possible to achieve the effect of a text view within a larger container.

How to use Recyclerview inside Scrollview [duplicate]

This question already has answers here:
RecyclerView inside ScrollView is not working
(26 answers)
Closed 7 years ago.
I'm trying to show horizontal recyclerview items and vertical recyclerview items inside an ScrollView
Scrollview didn't work even If i use android:fillViewport="true"
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
//Horizontal Recyclerview items
<RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RecyclerView>
//vertical Recyclerview items
<RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"></RecyclerView>
</LinearLayout>
</ScrollView>
You should use NestedScrollView instead. However you may need to write your own LayoutManager. Check out this SO Answer for more details
You need to use a custom layout manager to use recyclerview inside a scrollview.
You can remove the scrollview and make a header item in the vertical recyclerview which contain the horizontal recyclerview.
Also you should not use a recyclerview inside a scrollview. So think the second approach will be better.
Also you can can use Snap-RecyclerView-Utils.
It has a linear layout manager for recyclerview inside a scroll view and an adapter which can help you make a header containing you horizontal recyclerview.
ScrollView can only have one child.
Remove your RelativeLayout and try again.
Apart from that android:layout_height in ScrollView should be set to wrap_content
Additionally I'm not quite sure, if it works, since in the Docs it is stated that
You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.
Maybe a NestedScrollView works since it is for
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.

ListView inside two LinearLayout and scrolling issue

I have this structure
<LinearLayout
android:id="#+id/1">
<LinearLayout
android:id="#+id/2" />
<LinearLayout
android:id="#+id/3">
<ListView
android:id="#android:id/list" />
</LinearLayout>
</LinearLayout>
And I populate the ListView with some data. Well my problem is that the ListView becomes scrollable (while the LinearLayout number 1 fits the screen without scrolling), but what I want is this View to become full height and that the LinearLayout with id=1 becomes scrollable.
Inside ListView number 2 I have some TextViews, etc.
ListView's are scrollable by default if when the content is more than its display area.
However, LinearLayout would need to have a ScrollView in order to scroll.
Red Alert - You cannot use ScrollView and ListView together. You will end up seeing un-expected.
Alternate Solution: Prioritize what is more important to you, if scrolling the entire screen then add a ScrollView (provided your ListView items are static) else I will to wait to hear a good solution on this one. :)
Add ScrollView for ListView.
ScrollView will work for only one child view, so you have to add like this
LinearLayout
LinearLayout
LinearLayout
ScrollView
ListView...../ListView
/ScrollView
/LinearLayout

Categories

Resources