NestedScrollView with RecyclerView in it is not scrolling
I have tried all the options discussed in this forum .. looks like I am still missing something.. Please see my code my below.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="message"
type="Post" />
</data>
<android.support.v4.widget.NestedScrollView
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"
>
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
style="#style/MyCardViewStyle"
android:layout_marginBottom="5dp"
android:id="#+id/post_card1"
>
</android.support.v7.widget.CardView>
<android.support.v7.widget.RecyclerView
android:id="#+id/image_gallery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="LinearLayoutManager">
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.RecyclerView
android:id="#+id/doc_gallery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="LinearLayoutManager">
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.RecyclerView
android:id="#+id/post_replies"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="LinearLayoutManager">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</layout>
And I have set isNestedScrollingEnabled = false on all three RecyclerViews.
Screen just seems to be stuck and not at all scrolling
Create separate layout files for recycler views. And include those into the list view.
You have something like
<LinuearLayout ..>
<CardView>
<RecyclerView>
<RecyclerView>
<RecyclerView>
</LinearLayout>
You can change it to,
<LinuearLayout ..>
<include layout="#layout/cv1"/>
<include layout="#layout/rv1"/>
<include layout="#layout/rv2"/>
<include layout="#layout/rv3"/>
</LinearLayout>
This is just a clue to you. I did solve similar issues long back in past. Please try experimenting with this clue.
Related
I want base layout which is currently a included RecyclerView move above Bottomsheet when it opens. Same like adjustResize behaviour.
I tried to set anchor but it does not seem to work.
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<LinearLayout
style="#style/llDefault"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/layout_toolbar_single_chat" />
<TextView
android:id="#+id/tvOnlineStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="#dimen/space_small"
android:background="#drawable/bg_edittext_green"
android:padding="#dimen/space_small"
android:textColor="#color/white"
tools:text="Online" />
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<include
layout="#layout/layout_recycler_view_default"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/peek_height_bottomsheet"
app:layout_anchor="#+id/bottomSheet"
app:layout_anchorGravity="bottom|end" />
<include
android:id="#+id/bottomSheet"
layout="#layout/layout_bottom_options_single_chat" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
</layout>
I am stuck since 1 hour in this.
Try to change this app:layout_anchorGravity="bottom|end" to app:layout_anchorGravity="top"
Note:-
And to get the advantages of coordinator layout behaiour features , the views need to be direct child of the corrdinator layout.
Hope this helps.
I have following activity
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/coordinator">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorWhite"
android:id="#+id/catalog_view">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="79dp"
android:background="#color/gray238"
android:id="#+id/top_separator"/>
..
</android.support.constraint.ConstraintLayout>
<include layout="#layout/check_view_sheet"/>
</android.support.design.widget.CoordinatorLayout>
check_view_sheet
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/check_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="500dp"
android:background="#color/colorWhite"
android:orientation="vertical"
app:behavior_hideable="false"
app:behavior_peekHeight="80dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<FrameLayout
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:layout_width="400dp"
android:layout_height="235dp"
android:id="#+id/catalog_view_check_fragment"
/>
<TotalView.TotalView
android:layout_width="match_parent"
android:layout_height="#dimen/totalViewHeight"
android:id="#+id/catalog_total_view" />
</LinearLayout>
View inside framelayout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/check_recycler_view"
android:paddingBottom="#dimen/checkBottomPadding"
android:clipToPadding="false"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
</android.support.v7.widget.RecyclerView>
</android.support.constraint.ConstraintLayout>
The problem is that recycler view is not scrolling.
I tried wrapping framelayout in nestedScrollView, but performance of scroll is horrible - its very laggy and it hides sheet when I try to scroll recycler view down.
How canto fix this ?
Because you are trying do nested scrolling, bottom sheet has scrollable behavior.
try this in RecyclerView
android:nestedScrollingEnabled="true"
if scrolling it in bottom sheet is really mandatory otherwise try by setting it to "false".
First I need to scroll my NestedScrollView to the top, but smoothScrollTo(0, 0) doesn't work for me (page just jumping a bit). Second I wonder how can I scroll to a certain view inside my NestedScrollView. API 27, Support 27.0.2.
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data/>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/PageBackground"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical"
android:paddingBottom="#dimen/indent_page_bottom">
...
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</layout>
Try using fling to achieve smooth scrolling :
nestedScrollView.fling(0);
nestedScrollView.smoothScrollTo(0, 0);
I had a nestedscrollviewand inside it there is recyclerview. I tried smoothScrollTo(0, nsv_main.top). Didn't work. I gave an id to nestedscrollview like below
<android.support.v4.widget.NestedScrollView
android:id="#+id/nsv_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/PageBackground"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical"
android:paddingBottom="#dimen/indent_page_bottom">
...
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
and gave nsv_main.scrollY = 0 in my click event. It worked, even though its not a smooth scroll.
I am using NestedScrollView in tab layout and when I implemented RecyclerView in NestedScrollView 2 problems occur:
Toolbar is not hiding.
RecyclerView in not scrolling smoothly.
Here is my Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:background="#fff"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:layout_below="#+id/toolbar"
android:id="#+id/recyclerView"
android:background="#fafafa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
use recylerView.setNestedScrollingEnabled(false); to make your scrolling smoother.
Create separate layout files for views and try. And include those into the list view.
<LinuearLayout ..>
<include layout="#layout/cv1"/>
<include layout="#layout/rv1"/>
<include layout="#layout/rv2"/>
<include layout="#layout/rv3"/>
</LinearLayout>
This is just a clue to you. I did solve similar issues long back in past. Please try experimenting with this clue.
To begin with, I am aware of Recycler problems in old versions of libs. My current version of lib is 24.2.1.
I am trying to make a template, which contains a basic information about the item, and below this information, a list of comments. This list of comments has to wrap it's content and has to scroll with it's parent, so it should feel like a one big view.
I'm trying to do it with the following code, but RecyclerView doesnt wrap content, instead of this it has a small part on the bottom on the screen.
<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_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="50dp">
<android.support.v7.widget.Toolbar android:id="#+id/toolbar"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="#layout/news_layout_header_repost"/>
<LinearLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/cardview_inner_margin"
android:layout_marginEnd="#dimen/cardview_inner_margin"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:id="#+id/repostTextLayout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/loadComments"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:id="#+id/rv"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</ScrollView>
</LinearLayout>
Can you please help me?
UPDATE
Finally found the solution. It is better to use Relative layout. Not sure why this problem came up in LinearLayout, but the following xml structure worked:
<ScrollView>
<RelativeLayout>
<LinearLayout/>
<RecyclerView/>
</RelativeLayout>
</ScrollView>
ScrollView should never have a wrap_content height
manage the height of recyclerview according to the number of child items it contain, it may solve the height issue