RecycleView is not visible when its set inside a NestedScrollView in android - android

How to use RecyclerView inside NestedScrollView? RecyclerView content is not visible after setting adapter.
Anyway, I have already tried with RecyclerView inside NestedScrollView by adding a viewgroup like framelayout or relativelayout as a single child of nestedscrollview and then I added a recyclerview inside framelayout or relativelayout)
Thanks in Advance...
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorWhite">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/appbar"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/profile_bg_clound"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp">
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_driverRequests"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

Replace your RecycleView with this...
<com.app.view.CustomRecyclerView
android:id="#+id/rv_driverRequests"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
Hope this will work.

Related

Unable to scroll view pager in nested scroll view layout

I have view pager and swipe refresh view under nested scroll view.It is working fine but problem is view pager is not scrolling only recycler view is scrolling below view pager.I want to scroll layout.
This is my xml code below:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Home"
android:orientation="vertical"
android:id="#+id/linearHome"
android:paddingBottom="16dp"
android:layout_marginTop="10dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:layout_marginBottom="50dp">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progress2"
android:layout_centerInParent="true"/>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="130dp"
android:id="#+id/homeOffers"/>
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/indicator"
app:tabGravity="center"
app:tabIndicatorHeight="0dp"
app:tabBackground="#drawable/tab_selector"/>
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/refresh">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/recycle"/>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout>
SCREENSHOT
As seen in screenshot view pager is set fixed on top and recycler view is scrolling below. I want to scroll view pager also some one please let me know how can I achieve desired layout. Any help would be appreciated.
THANKS
Replace your recyclerView with,
<android.support.v7.widget.RecyclerView
android:id="#+id/recycle"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
here,
app:layout_behavior="#string/appbar_scrolling_view_behavior"
will manage the rest of things.
Just add app:layout_behavior="#string/appbar_scrolling_view_behavior" in your NestedScrollView to scroll its child layouts and also remove android:scrollbars="none" from NestedScrollView.
To scroll the whole layout all we need to wrap nested scroll view under swipe refresh layout and this will scroll the whole layout.
Updated layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".Home"
android:orientation="vertical"
android:id="#+id/linearHome"
android:paddingBottom="16dp"
android:layout_marginTop="10dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:layout_marginBottom="50dp">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progress2"
android:layout_centerInParent="true"/>
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:id="#+id/nobook"
android:src="#drawable/nobook"
android:layout_centerInParent="true"
android:visibility="gone"/>
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/refresh">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scroll"
android:scrollbars="none"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="130dp"
android:id="#+id/homeOffers"/>
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/indicator"
app:tabGravity="center"
app:tabIndicatorHeight="0dp"
app:tabBackground="#drawable/tab_selector"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/recycle"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
THANKS

scroll views and RecyclerView at same time

want to scroll RecyclerView and views in scroll view, in this code scroll only work on views but not scroll the RecyclerView or scroll hide the RecyclerView.I am using nested scrollview but same not working.
scroll views and RecyclerView like as one layout is scrolling.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="#+id/scrol"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/topRl5"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/nested_scrol"
android:orientation="vertical"
android:visibility="visible">
<com.github.mikephil.charting.charts.BarChart
android:id="#+id/chart1"
android:layout_width="match_parent"
android:layout_height="#dimen/_300sdp"
android:layout_below="#+id/weekly_summary"
android:visibility="visible" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#color/grey_light"
android:gravity="center"
android:padding="#dimen/_5sdp"
android:text="تفصیلی رپورٹ"
android:textSize="#dimen/_15sdp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/daily_earning_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/scrol"
android:visibility="visible">
<include
layout="#layout/weekly_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</RelativeLayout>
Here is my RecyclerView i include it in main class
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:showIn="#layout/activity_barchart"
tools:context=".guaranteeDetails.baarChart.BarChartActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/weekly_recycler_view"
android:layout_marginRight="#dimen/_4sdp"
android:layout_marginLeft="#dimen/_4sdp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
Use should use NestedScrollView instead of ScrollView
And I would also recommend setting
Recyclerview.setNestedScrollingEnabled(false);

Allow only One view that has ablility to scroll the CoordinatorLayout . eg.like Handle view work in Sliding panel

I have search a lot but not found same question on stack-overflow
Problem - I just want that only one view that scroll CoordinatorLayout similar
like handle view work in Sliding Panel layout
but in my current layout i have two views one is handle view (Textview with text "Route Plan") and other is RecyclerView What I want is when user click and drag on handle view CoordinatorLayout should scroll but when user click on RecyclerView it should not scroll CoordinatorLayout it shoud scroll only RecyclerView items is it possible
here is my current layout -
<?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:background="#drawable/bg_sub_tab"
android:padding="5pt"
tools:ignore="RtlHardcoded">
​
<android.support.design.widget.AppBarLayout
android:id="#+id/materialup.appbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="50dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
​
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?colorPrimary"
app:expandedTitleMarginBottom="94dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/tvRoutePlan"
android:layout_alignParentTop="true"
android:gravity="top">
<RelativeLayout
android:id="#+id/mapContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</android.support.design.widget.CollapsingToolbarLayout>
​
</android.support.design.widget.AppBarLayout>
​
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
app:layout_behavior="#string/appbar_scrolling_view_behavior"><!--com.indus.corelib.ui.FixedScrollingViewBehavior -->
<TextView
android:id="#+id/tvRoutePlan"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#drawable/map_list_title_gradient"
android:drawSelectorOnTop="true"
android:gravity="center_horizontal|center_vertical"
android:padding="5pt"
android:text="Route Plan"
android:textColor="#android:color/white"
android:textSize="25sp"
android:visibility="visible"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.v4.widget.NestedScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="true"
android:nestedScrollingEnabled="false"
android:background="#android:color/transparent"
android:cacheColorHint="#android:color/white"
android:descendantFocusability="blocksDescendants"
android:divider="#android:color/darker_gray"
android:dividerHeight="#dimen/divider_height"
android:drawSelectorOnTop="true"
android:smoothScrollbar="true" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
Note :- when i used other view insted of RecyclerView than it work perfectly as i want like when i click and drag that view CoordinatorLayout not move but i need recycler view there to show list :(
So try do something like this:
<?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:background="#drawable/bg_sub_tab"
android:padding="5pt"
tools:ignore="RtlHardcoded">
​
<android.support.design.widget.AppBarLayout
android:id="#+id/materialup.appbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="50dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
​
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?colorPrimary"
app:expandedTitleMarginBottom="94dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/tvRoutePlan"
android:layout_alignParentTop="true"
android:gravity="top">
<RelativeLayout
android:id="#+id/mapContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</android.support.design.widget.CollapsingToolbarLayout>
​
</android.support.design.widget.AppBarLayout>
​
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
app:layout_behavior="#string/appbar_scrolling_view_behavior"><!--com.indus.corelib.ui.FixedScrollingViewBehavior -->
<TextView
android:id="#+id/tvRoutePlan"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#drawable/map_list_title_gradient"
android:drawSelectorOnTop="true"
android:gravity="center_horizontal|center_vertical"
android:padding="5pt"
android:text="Route Plan"
android:textColor="#android:color/white"
android:textSize="25sp"
android:visibility="visible"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="true"
android:nestedScrollingEnabled="false"
android:background="#android:color/transparent"
android:cacheColorHint="#android:color/white"
android:descendantFocusability="blocksDescendants"
android:divider="#android:color/darker_gray"
android:dividerHeight="#dimen/divider_height"
android:drawSelectorOnTop="true"
android:smoothScrollbar="true" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
So remove recycleview from your layout behavior parent. Because the recycleview isnt inside the layout behavior parent he dont do the scroll flag. If this not Works the oter way is put the CoordinatorLayout inside other layout like a LinearLayout and recycleview outside CoordinatorLayout but inside LinearLayout.
Note: It's my idea i don't know if it Works.
Yup , I got the answer by myself
Just stop scroll of RecyclerView and it just work what i want
<android.support.v7.widget.RecyclerView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:cacheColorHint="#android:color/white"
android:descendantFocusability="blocksDescendants"
android:divider="#android:color/darker_gray"
android:dividerHeight="#dimen/divider_height"
android:drawSelectorOnTop="true"
android:nestedScrollingEnabled="false"
android:overScrollMode="never"
android:fadeScrollbars="false"/>
also i used in java file
mListView = (RecyclerView) rootView.findViewById(android.R.id.list);
mListView.setNestedScrollingEnabled(false);
mListView.setOverScrollMode(ListView.OVER_SCROLL_NEVER);
mListView.stopScroll();
mListView.stopScroll() This is real game changer
But i am not happy that no one try to solve my prob except Bruno Ferreira :( Thanks Bruno for help

How to Handle Scrollview Slow Android

im used two recyclerview in one layout, and if i want to both recylerview can scroll, i adding Nested Scrollview.
Maybe like this:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/NestedScrollView"
android:layout_below="#+id/toolbar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/xx"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/arrayListUser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:divider="#color/white">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="#color/line"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/arrayList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:divider="#color/white">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
two Recylerview in one Nestedscrollview make slow scroll. so, how to handle to make it fast?
set setNestedScrollingEnabled to false
mRecyclerView.setNestedScrollingEnabled(false);
and also in the layout
<android.support.v7.widget.RecyclerView
...
android:nestedScrollingEnabled="false"/>
Which Enables or disables nested scrolling for this view.

NestedScrollView in fragment with TabLayout & ViewPager not able to scroll

I added NestedScrollView into my fragment as following code snippet.
I'm using FragmentPagerAdapter to display fragment content in ViewPager. (following this article)
Content is populating properly but I'm not able to scroll.
main_fragment.xml
<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:weightSum="1"
android:background="#color/feed_grey_background" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/default_gap_1_5x">
</LinearLayout>
<android.support.design.widget.TabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:color/holo_blue_light" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
tabview_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/postList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
update
I'm able to scroll recycler view (not nestedscrollview) if I remove recyclerView.setNestedScrollingEnabled(false);

Categories

Resources