Using Recycler view inside Sticky Scroll view not working - android

I have a requirement where I need to code a screen which has a info view in top and view pager with two tabs in the bottom. View pager has two tabs with Recycler View inside it.
The View pager should stick whenever the user scrolls up and then the recycler view inside it should start scrolling. To achieve this I created two separate fragments for top part and bottom part and wrote the xml like this.
<com.citi.mobile.dashboard.views.StickyScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/core_color_FFFFFF_white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/title_id"
layout="#layout/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#+id/top_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>
<FrameLayout
android:id="#+id/bottom_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:tag="sticky">
</FrameLayout>
</LinearLayout>
Inside the the bottom container I have a View Pager.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="#+id/TransTabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabIndicatorColor="#color/core_color_0077bb_blue"
app:tabMode="fixed"
app:tabSelectedTextColor="#color/core_color_0077bb_blue"
app:tabTextAppearance="#style/ledgerTabLayoutTextAppearance"
app:tabTextColor="#color/core_color_666666_grey"
custom:typefaceName="Roboto-Medium" />
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/transaction_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
This has two tabs and each has a recycler view inside this. When I run this the parent scrollview stops working and only the recyclerview scrolling works.

Try adding android:nestedScrollingEnabled="false" to the recyclerview in your xml.

Related

Scrolling ImageView along with Recylcer View

So,
I have a layout.xml file which contains a Recycler View. Now, what I want is, I added two image Views on top of this Recycler View but I want those ImageViews to scroll with the RecyclerView as well.
I just wanted to ask, is this possible to do? And if yes, how can I achieve this?
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/content_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<include
android:id="#+id/header_bar"
layout="#layout/section_header" />
<ImageView-1>
<ImageView-2>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/category_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingHorizontal="#dimen/category_grid_edge_space"
android:paddingTop="#dimen/category_grid_padding_top"
android:scrollbarSize="#dimen/grid_padding"
android:scrollbarStyle="outsideOverlay"
android:scrollbarThumbVertical="?android:attr/textColorSecondary"
android:scrollbars="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Put your RecycleView in NestedScrollView
<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:orientation="vertical">
<include
layout="#layout/your_header"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/category_grid"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
also don't forget to disabled NestedScrolling for RecyclerView
myRecyclerView.setNestedScrollingEnabled(false);
OR
Add those views as a header. Here is a good guide on how to add a custom item view: https://medium.com/androiddevelopers/get-ahead-using-headers-in-recyclerview-2909a69b19
https://github.com/masudias/RecyclerView-with-Header-and-Footer
You can use header and footer i

How make put ViewPager inside ScrollView and scroll all view as one part?

I have an activity that have viewpager inside scrollview like the follwoing
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--someViews-->
</LinearLayout>
<!--then viewPager-->
<androidx.viewpager.widget.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
Then the view pager holds some fragments which have a tall view too.
The problem is the scroll view not scrolling because of the view is not need to scroll but the view inside the viewpager fragment's not scrolling
so, Is it possible to make the whole view including the inside view pager scroll as one view?
What I am saying that I don't need to scroll the viewpager fragment as separated part I need to scroll it as part of activity view.
Thanks
I believe the setup you are looking for would work inside a CoordinatorLayout using the NestedScrollView widget like so:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Display1" />
<TextView
android:id="#+id/subTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/subtitle"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Body1" />
<androidx.viewpager.widget.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="300dp" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
I have just tested this with a sample project with a single text view in a Fragment and I was able to both scroll the view and swipe through the pages.
Please note though: I did have to provide a specific height for the ViewPager in order for it to display.

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>

How to make view under view clickable?

I have the recycler view scroll over the top of the toolbar but the toolbar items (eg. home button) are not clickable.
My layout:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/primary">
<include
android:id="#id/toolbar_feed"
layout="#layout/toolbar_feed"/>
// Inside viewPager is recycler view which scroll over the toolbar
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include
android:id="#+id/navigation_bottom_layout"
layout="#layout/bottom_navigation_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
My only problem is that toolbar home button is not clickable because it is behind viewPager layer. It can work with playing translationZ but it only support API21+. So, you guys have an idea to make this work?
Change the order in which you add the views in their parent.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/primary">
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<include
android:id="#id/toolbar_feed"
layout="#layout/toolbar_feed"/>
<include
android:id="#+id/navigation_bottom_layout"
layout="#layout/bottom_navigation_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>

Bottom navigation overlapping recycler view contents in android

I am using bottom navigation view and displaying three tabs,In one of the tab i have added recycler view, but the contents are overlapped by bottom navigation.Not able to scroll recycler view.Is there any way that i can hide the bottom navigation when i scroll item on recycler view.
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:sv="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".activity.patient.PatientsActivity">
<include
layout="#layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:id="#+id/asd"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="60dp"
android:orientation="vertical">
<co.moonmonkeylabs.realmrecyclerview.RealmRecyclerView
android:id="#+id/appointmentsList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:rrvEmptyLayoutId="#layout/empty_view"
app:rrvLayoutType="LinearLayout"
app:rrvSwipeToDelete="true" />
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/white"
app:layout_behavior=".BottomNavigationBehavior"
app:menu="#menu/bottom_navigation_main" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout> </android.support.v4.widget.DrawerLayout>
image
First i think you could add an:
android:layout_above="#id/bottom_navigation"
To the Recyclerview
For the Scrolling part i would suggest looking for a ScrollingBehaviour
like in this question:
How to scroll up/down of bottom bar on scrolling of RecyclerView
add NestedScrollView just before RecyclerView this may work like above
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<co.moonmonkeylabs.realmrecyclerview.RealmRecyclerView
android:id="#+id/appointmentsList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:rrvEmptyLayoutId="#layout/empty_view"
app:rrvLayoutType="LinearLayout"
app:rrvSwipeToDelete="true" />
</android.support.v4.widget.NestedScrollView>

Categories

Resources