how to scroll RecyclerView in scrollview - android

how to scroll all above RecyclerView in scrollview
I have to implement RecyclerView in scrollview show as below code, but not scroll RecyclerView.
please give answer
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/horizontalScrollView"
android:layout_marginTop="10dp">
<RelativeLayout...
<android.support.v7.widget.RecyclerView
android:id="#+id/rvpouch"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false"
android:layout_below="#+id/textView3">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
</ScrollView>

Don't use RecyclerView inside ScrollView. Use NestedScrollView instead of ScrollView.
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.
For Example:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false">
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false">
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_three"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Use attribute android:nestedScrollingEnabled="false" for smooth scrolling.

Use NestedScrollView instead of scroll view and set
recyclerView.setNestedScrollingEnabled(false);

Following code snippet will help you to implement scrolling using ScrollView of RecyclerView
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarSize="3dp"
android:scrollbarThumbVertical="#drawable/scrollbar_black">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/rlFiltersSearchEvent"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#drawable/action_bar_gradient">
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rvListOfEventsMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/fab_margin"
android:layout_below="#+id/rlFiltersSearchEvent"
android:nestedScrollingEnabled="false"
android:scrollbars="none" />
</RelativeLayout>
</ScrollView>
Hope it helps

Related

Android recycler view inside on scrollview [duplicate]

This question already has answers here:
RecyclerView inside ScrollView is not working
(26 answers)
Closed 2 years ago.
i have
MAIN VIEW
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_products"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
/>
</ScrollView>
On my template adapter, i have a another recycler adapter for child views
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:id="#+id/title_product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:background="#color/GRAY"
android:text="TextView" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_for_specification_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:nestedScrollingEnabled="false"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
The code work, but when user scroll on android device, the parent scrollView does not allow me to scroll over the recycler view (1)
Use NestedScrollview instead of scrollview and use android:nestedScrollingEnabled="false" for recycler_products recyclerview not in both
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_products"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
/>
</androidx.core.widget.NestedScrollView>
If you are not able to scroll it is because of this line
android:nestedScrollingEnabled="false".
Change it to True, so you can enable the scrolling:
android:nestedScrollingEnabled="true".
In you code you have recylerview inside scroll view, this is wrong.
Option 1: If scroll view has not any other child view than remove it and just use recyclerview and also remove android:nestedScrollingEnabled="false
And your Main View code looks like this;
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_products"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
Option 2: If scroll view has also other child including recyclerview than you should use nestedscrollview like below code:
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:orientation="vertical">
<ImageView
android:id="#+id/sellerProduct"
android:layout_width="match_parent"
android:layout_height="200dp"
android:adjustViewBounds="true"
android:src="#drawable/iphone"
android:scaleType="fitXY"
android:contentDescription="#string/app_name" />
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:nestedScrollingEnabled="false
android:id="#+id/productList"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>

Add View at top of recycler view

In my android application, there is a slideshow at top of page and below it, there is a recycler view, my problem is how to add the slideshow above recycler view in a way that slideshow can be scrolled with recycler view. I tried adding a scroll view as a parent but it seems that recycler lost the recycling power.
<RelativeLayout
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:background="#ececec">
<android.support.v4.view.ViewPager
android:id="#+id/ChefFragmentViewPager"
android:layout_width="match_parent"
android:layout_height="220dp"
android:layout_alignParentTop="true" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/ChefFragmentViewPager"
android:background="#ececec"
android:scrollbars="none" />
</RelativeLayout>
Try using NestedScrollView instead of ScrollView and also set recyclerView.setNestedScrollingEnabled(false); programmatically.
Try this code and let me know if it helped you or not:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
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:background="#ececec">
<android.support.v4.view.ViewPager
android:id="#+id/ChefFragmentViewPager"
android:layout_width="match_parent"
android:layout_height="220dp"
android:layout_alignParentTop="true" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/ChefFragmentViewPager"
android:background="#ececec"
android:scrollbars="none" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>

NestedScrollview inside a Recycler view not scrolling

I am creating an Android program. In this program, I have a ScrollView inside of which there is a RecyclerView. I am adding data in this RecyclerView via a RecyclerViewAdapter.
For each item of the RecyclerView, there is a NestedScrollview having a single LinearLayout of vertical orientation. I am dynamically adding ImageView in this LinearLayout.
The problem is that the images are not scrolling. In very rare scenarios (by tapping so many times on screen), it got scrolled for once.
Could anybody help me on this?
Here is the code -
Parent Recycler View :-
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/id_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#color/gray3"
android:dividerHeight="5sp"
android:paddingLeft="2sp"
android:paddingTop="5sp"
android:paddingRight="2sp"/>
<com.app.sh.widget.WrappedGridView
android:id="#+id/gridView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/White"
android:numColumns="2">
</com.app.socialhand.widget.WrappedGridView>
</LinearLayout>
</ScrollView>
And the Item of the Recycler View :-
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/vScrollView"
android:layout_below="#id/iv_up"
android:layout_above="#+id/iv_down"
android:isScrollContainer="true"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/ll_123"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</LinearLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
I am dynamically adding the ImageViews in ll_123.
Try to use NestedScrollView instead of ScrollView or remove it. RecyclerView has own scrollview which will conflict with ScrollView.
You can try a structure like:
<ScrollView>
<NestedScrollView>
<LinearLayout>
<RecyclerView/>
</LinearLayout>
</NestedScrollView>
</ScrollView>
And ListItem layout should contain:
<NestedScrollView>
<LinearLayout/>
</NestedScrollView>
Check if this works correctly...
I got simmilar problem and this helped me:
<ScrollView
android:id="#+id/messages_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/send_panel"
android:fillViewport="true"
android:padding="5dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/messages"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:animateLayoutChanges="true"
android:gravity="center_horizontal|bottom"
android:orientation="vertical">
</LinearLayout>
</RelativeLayout>
</ScrollView>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<-only one layout in nestade layout->
<LinearLayout
android:id="#+id/activity_edit_existing_location"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/rcl"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<-put here yr second layout code->
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

How to make ScrollView scroll smoothly

I want to use RecycleView in ScrollView, but when I do so my scrolling view fixes the moment I stop scrolling. How to make it more smooth?
Here is my xml file used:
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"/>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fastScrollEnabled="true"
android:layout_marginTop="143dp"
android:scrollbars="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</ScrollView>

cardview is not wrapping the content inside swipeview

I Want to display an listview inside an Cardview.
This is the Code I used :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="20dp">
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/list_layout_with_fab_list_view_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardCornerRadius="4dp">
<ListView
android:id="#+id/list_layout_with_fab_list_view"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:divider="#null"
android:fastScrollEnabled="true"
android:listSelector="#android:color/transparent"
android:outlineProvider="none" />
</android.support.v7.widget.CardView>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
If i remove the SwipeView the CardView is wrapping the content. but i need both swipeview as well as CardView.
Is there anything i have done wrong??
You want to wrap a content inside cardview make sure that your card view height should set to height which is able to handle the content inside just give height in numbers and check weather it handles your content or not.Use this code in your layout and check if it works or not and in #dimes/fab_margin you can set the height for your cardview.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="#dimen/fab_margin"
app:cardCornerRadius="2dp"
app:cardElevation="6dp"
android:layout_alignParentBottom="true"
>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listView">
</ListView>
</android.support.v7.widget.CardView>
</RelativeLayout>

Categories

Resources