How to use RecyclerView with NestedScrollView? - android

I want to make a scrolling at LinearLayout and disable scrolling from RecyclerView. I tried changing LinearLayout to NestedScrollView but it doesn't work and i don't know why.
I've tried this question but it doesn't work well. The content in RecyclerView can be loaded dynamically from WS and it's an endless scroll. The screen was freezing when content in RecyclerView updated.
I've seen this from Twitter, how can we do this https://drive.google.com/file/d/0B2JZggeoXKKFdG1ENmZEdWFIa0k/view?usp=sharing
Example
This is my simple screen of my app, i want scrolling at red currently, and it currently scrolls at 'blue'. Many thanks.
Code
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_margin="16dp"
android:background="#CCC"
android:id="#+id/imageView2" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Image caption"
android:background="#cbffa3"
android:padding="16dp"
android:id="#+id/textView8" />
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Tried but not work, contents inside RecyclerView not showing
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_margin="16dp"
android:background="#CCC"
android:id="#+id/imageView2" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Image caption"
android:background="#cbffa3"
android:padding="16dp"
android:id="#+id/textView8" />
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

Option 1: Use WRAP_CONTENT on RecyclerView and put it in a scroll view along with other widgets. WRAP_CONTENT on RecyclerView works only with 23.2 though. This is not a recommended way as if use WRAP_CONTENT your RecyclerView items won't get recycled and it slow down the UI when the content gets long.
Option 2: Use types for the recycler view adapter and render a different view for index 0. This answer shows how to do it.
Option 3: The best option of achieving this kind of experience is using CollapsingToolbarLayout. Your top content will collapse when you scroll up and you'll be able to scroll the RecyclerView.
Here is one way of replicating the Twitter page with CollapsingToolbarLayout.
<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:layout_gravity="center"
android:fitsSystemWindows="false"
android:orientation="vertical"
app:statusBarBackground="#android:color/transparent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?actionBarSize"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="#android:drawable/btn_star_big_on"
app:layout_collapseMode="none"
/>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="#android:color/transparent"
android:elevation="5dp"
android:importantForAccessibility="yes"
app:layout_collapseMode="pin"
app:layout_scrollFlags="exitUntilCollapsed">
<TextView
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:background="#android:color/white"
android:text="Title Here"
/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
More about this is in the Android Blog - http://android-developers.blogspot.ca/2015/05/android-design-support-library.html (Scroll to "CoordinatorLayout and the app bar")

I recommend you to add a listener to the scroll view and detect if the user scrolls down, you "hide" the top. The easiest way is to use the default "Scroll Activity" that comes on the default menu when you create a new Activity in Android Studio using Material Design.

Related

Android recyclerview not scrolling on lower end devices with sticky header - why?

i have this issue where my recyclerview does not do nestedscrolling on api 19 (lollipop) ...on latest version of android its ok.
using following dependency: com.android.support:design:26.1.0
and what i have created is a recyclerview that should have a sticky header. the header is in a cardview and the list items are below the cardview. it looks like this:
detailscreen.xml:
<!--wrapping in RelativeLayout until this is resolved: https://stackoverflow.com/questions/57142959/why-latest-version-constraintlayout-doesnt-work-in-nestedscrollview-with-coordi-->
<RelativeLayout 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:orientation="vertical">
<androidx.cardview.widget.CardView
android:id="#+id/headerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<TextView
android:id="#+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/ride_hail_meet_at"
android:textColor="#388bf2"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_weatherdata"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:nestedScrollingEnabled="false"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintLeft_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/tv_description"
tools:itemCount="3"
tools:listitem="#layout/weather_data_row_item"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<RelativeLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/headerView"
android:layout_alignParentBottom="true"
android:background="#color/white">
<!-- THIS IS THE RECYCLERVIEW GIVING ME THE PROBLEMS. ITS NOT SCROLLING ON API 19 , WHY ??? -->
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_directions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="5"
tools:listitem="#layout/ride_direction_row" />
</RelativeLayout>
when i inflate this thing its placed inside a CoordinatorLayout customView. that container itself can be scrolled. What am i doing wrong that it works on recent versions of android but not lollipop ? i even tried using a appBarLayout and putting my headerView in that but same thing just on older version of android, not working. im open to changing the xml entirely if you can suggest a better approach ?
note: setting android:nestedScrollingEnabled = false is going to cause my recyclerView not to recyclerviews. i have big images in the list so i need this feature.
You'd have to set android:layout_height to match_parent or a fixed size.
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent" />
If you set it to wrap_content it'll expand to the size of its content and thus not scroll.
so odd this is the only way i could get it resolved:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleGravity="bottom"
app:expandedTitleMarginEnd="#dimen/activity_horizontal_margin"
app:expandedTitleMarginStart="#dimen/activity_horizontal_margin"
app:layout_scrollFlags="noScroll"
app:title="#string/app_name">
<ImageView
android:id="#+id/toolbar_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:contentDescription="#null"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="#drawable/beach_huts" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
so strange this works for everything ..thanks everyone. they key thing is i need to put the recyclerView FIRST above everything else. then define the appbar stuff afterwards.

CoordinatorLayout with NestedScrollView behavior

I am a Android newbie programmer and I am stuck with a UI problem. My goal is to achieve something closer to this:
desirable layout
I thought about it and I decided to do it with a CoordinatorLayout, AppBarLayout / CollapsingToolbarLayout and a NestedScrollView with a CardView. Sounds just fine for this problem, right?
With my actual XML I already have the toolbar, image and the scroll feature.
However, the scroll feature isn't 100% like I wanted. First of all, it's not possible to scroll down since around mid screen (probably because of android:layout_height="275dp"), it is only possible to scroll up. (and of course collapse the toolbar). My main goal is to "open" the image fullscreen. Do you have any idea how can I achieve this behaviour? Maybe controlling % in .java?
Also have one annoying bug, but I can leave with it for now, just try to help if it also gives you some OCD condition
I tried to add an transparent property to my LinearLayout but it didn't work.
Normal scroll:
Current scroll
Buggy 'panel' as it is close to collapse:
buggy panel image
My all XML:
<android.support.design.widget.CoordinatorLayout
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:id="#+id/annonce.main.coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="RtlHardcoded"
>
<android.support.design.widget.AppBarLayout
android:id="#+id/flexible.example.appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/flexible_example_collapsing"
android:layout_width="match_parent"
android:layout_height="275dp"
app:title="Mosteiro dos Jerónimos"
app:expandedTitleMarginBottom="94dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleTextAppearance="#style/CollapsingTextAppearance.Inverse"
app:contentScrim="?attr/colorPrimary"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:src="#drawable/mosteiro_dos_jeronimos"
android:scaleType="centerCrop"
/>
<android.support.v7.widget.Toolbar
android:id="#+id/flexible.example.toolbar"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#null"
app:layout_collapseMode="pin"
app:title="Mosteiro dos Jerónimos"
style="#style/ToolBarWithNavigationBack"
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
app:behavior_overlapTop="78dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.v7.widget.CardView
android:id="#+id/flexible.example.cardview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentPaddingBottom="16dp"
app:contentPaddingLeft="16dp"
app:contentPaddingRight="16dp"
app:cardCornerRadius="16dp"
app:cardBackgroundColor="#android:color/white"
app:cardElevation="4dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<View
android:id="#+id/myRectangleView"
android:layout_width="40dp"
android:layout_height="4dp"
android:layout_gravity="center"
android:layout_marginTop="4dp"
android:background="#drawable/rectangle"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Lisboa"
android:textAppearance="#style/TextAppearance.Header"
style="#style/TextComponent.ItemRow"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:lineSpacingExtra="8dp"
android:textSize="16sp"
android:text="#string/lorem"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/flexible.example.fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="32dp"
android:elevation="8dp"
android:src="#drawable/ic_adb_24dp"
app:layout_anchor="#id/flexible.example.cardview"
app:layout_anchorGravity="top|right|end"
tools:ignore="RtlHardcoded"
/>
</android.support.design.widget.CoordinatorLayout>
I think your layout is fine (works on my side), but maybe the behavior you want is more something like a Bottomsheet behavior.
Have you had a look at it?
Basically this will make you able something like google maps, so you would be able to scroll like you want.
Here is a tutorial to have a better understanding of what it is like.
Please let me know if this is what you're looking for.

Add items before recyclerview

I have an activity with a recycler view. But I need to add an image before recycler view (like instagram stories before feed). How do I implement it?
my xml file
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:title="Locations"
app:titleTextColor="#color/white" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/cropmap"
tools:listitem="#layout/item_marker" />
<ImageView
android:id="#+id/cropmap"
android:layout_width="match_parent"
android:layout_height="168dp"
android:background="#drawable/cropmap" />
<ProgressBar
android:id="#+id/main_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</android.support.design.widget.CoordinatorLayout>
Thanks!
The perfect way of doing this is to take advantage of "Item View type" in recyclerview. Basically what you should be doing is populating the image on top inside the recyclerview itself. The image will appear as the first item in recyclerview and other items will come subsequently. This can be implemented by using ItemViewType in recyclerview.
Some useful resources can be found here and here
<LinearLayout
android:layout_width="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:weightSum="10">
<ImageView
android:id="#+id/cropmap"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#drawable/cropmap"
android:layout_weight="3" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:scrollbars="vertical"
tools:listitem="#layout/item_marker"
android:layout_weight="7" />
</Linearayout>
<ProgressBar
android:id="#+id/main_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</android.support.design.widget.CoordinatorLayout>
Take advantage of the full potential of fragments. You can set a FrameLayout between your top bar and recyclerView, and then add a fragment there, or just simply use the <fragment> tag on your xml. For more info about flexible UI, please take a look in the Android documentation here.
Think of this fragment as your other section, like the Instagram example you just gave. There you can add what you want (ViewPager, HorizontalScrollView, etc), and be reflected when you inject the fragment in your layout.

RecyclerView inside NestedScrollView is not scrolling up when Image is collapsed

Here is a link to the whole project so that you can reproduce the problem:
https://github.com/FaridArbai/TapExchange/tree/master/TapExchange
I would like to ask for help with an issue that I've been struggling with for about two days and yet found no solution in spite of the thorough research that I have done.
Basically, I have an AppBarLayout with a CollapsingToolbarLayout inside whose mission is to collapse a background image when the user scrolls down a RecyclerView of CardViews. The problem arises when I try to scroll down that RecyclerView once the Image is fully collapsed: It won't scroll if I touch one of the cardviews that compose the RecyclerView!
Here is the look with no collapse (here I can scroll with no problem):
Uncollapsed Image, able to scroll in any direction
And here is the look once the image is collapsed (here I cannot scroll down if my finger touches any cardview that compose the RecyclerView):
Collapsed Image, unable to scroll down if I touch one of the cardviews
The code for the whole layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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=".profiles.PersonalProfile"
android:background="#FCFCFC">
<android.support.design.widget.AppBarLayout
android:id="#+id/personal_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/personal_collapsing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:contentScrim="?attr/colorPrimary"
app:title=""
app:titleEnabled="false">
<ImageView
android:id="#+id/personal_image_background"
android:layout_width="match_parent"
android:layout_height="340dp"
android:scaleType="centerCrop"
android:src="#drawable/profile_background"/>
<android.support.v7.widget.Toolbar
android:id="#+id/personal_toolbar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Space
android:id="#+id/avatar_collapsed_target"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="0dp"/>
<TextView
android:id="#+id/personal_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:text="Unknown Username"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/section_selection_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#drawable/ic_action_add" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/personal_image_foreground"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="120dp"
android:layout_gravity="top|center_horizontal"
android:src="#drawable/executive"
app:collapsedTarget="#id/avatar_collapsed_target"
app:layout_behavior="com.faridarbai.tapexchange.graphical.CollapsingAvatarBehavior"
android:elevation="5dp"/>
<LinearLayout
android:id="#+id/personal_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_anchor="#id/personal_image_foreground"
app:layout_anchorGravity="bottom|center"
android:paddingTop="30dp">
<TextView
android:id="#+id/username_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unknown Username"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</LinearLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/personal_nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:fillViewport="true">
<android.support.v7.widget.RecyclerView
android:id="#+id/personal_sections_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="0dp" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
I am building with the API 25 and using GUI utilities from version 25.4.0. I would be extremely grateful if anybody can help.
Thanks
EDIT
I tried with SDK nº 27 and 27.1.1 building tools, supressed both "snap" and the NestedScrollView and still got the same problem: Once the background image has collapsed the RecyclerView is unable to scroll up if I initially put my finger on a CardView from the RecyclerView. This is quite odd because WhatsApp, Facebook and Telegram use a very similar Layout and they don't have this problem so there should be a well accepted work around.
Anyone to help?
why you are using RecyclerView inside NestedScrollView?!. if yo have more items with different layouts you can use recyclerView With different ViewTypes but i won't recommend to use it inside NestedScrollView try to use it Directly and don't forget to put this app:layout_behavior="#string/appbar_scrolling_view_behavior" in the recylerView and it will work.

RecyclerView cutting off last item

We can see here last item is partially visible. How can i fix this?
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="#+id/coordinator_layout"
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="wrap_content"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<include
layout="#layout/header"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/grey_background">
<ImageView
android:id="#+id/image"
android:layout_width="#dimen/thumbnail_width"
android:layout_height="#dimen/thumbnail_height"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="fitCenter"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/image"
android:orientation="vertical"
android:padding="#dimen/participant_left_padding">
<TextView
android:id="#+id/participants_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="name"
android:textColor="#android:color/white"/>
<TextView
android:id="#+id/total_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="view"
android:textColor="#android:color/white"/>
<TextView
android:id="#+id/ranking"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ranking"
android:textColor="#android:color/white"/>
</LinearLayout>
<ImageView
android:id="#+id/overflow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="#drawable/ic_action_overflow"/>
</RelativeLayout>
I'm also having the same problem. In my opinion this happened because you set the AppBarLayout XML attribute android:fitsSystemWindows="true". To solve this i give the RecyclerView margin bottom equal to action bar size
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/recyclerView"
android:layout_marginBottom="?attr/actionBarSize">
#Lester was right problem was RecyclerView's wrap_content height. But changing match_parent was not working because. This layout was added to a fragment and that fragment was declared wrap_content. So I have changed fragment's height and recyclerview's height to match_parent and now problem solved.
<fragment
android:id="#+id/fragment"
android:name="com.example.fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
I had this problem with a RecyclerView inside a ConstraintLayout, and i changed my recyclerview constriants to "0dp" (match_constraint) and had no further trouble.
have a look
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- Title -->
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="#dimen/view_with_press_height"
android:text="#string/taxes_fees_charges"
android:gravity="center_vertical"
android:layout_marginStart="#dimen/general_side_margin"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<!-- Details Recyclerview-->
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/title"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="#dimen/general_bottom_margin"
app:layout_constraintVertical_bias="0.0"
tools:itemCount="28"
tools:listitem="#layout/tax_details_row" />
</android.support.constraint.ConstraintLayout>
if you want to use the tools:itemCount="28" you will have to import xmlns:tools="http://schemas.android.com/tools" in your XMLfile.
I tried all the available option from most of possible site but I didn't get the solution.
Then, I think can I use bottom padding? And Yes, It's work for me.
I am sharing the code to you.
Nothing more attribute required other than height, width & padding.
android:paddingBottom="?attr/actionBarSize"
<android.support.v7.widget.RecyclerView
android:id="#+id/your id name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="?attr/actionBarSize"
app:layout_constraintTop_toBottomOf="#+id/your field" />
Use RelativeLayout instead of ConstraintLayout.It's working for me.
I'm showing some solution but didn't work
Now I find one easy solution for this cutting off the last item in recycler view
Add your recycler view into LinearLaout
After adding recycler view into Linearlayout add these two Attributes into recycler view.
android:paddingBottom="?attr/actionBarSize"
android:clipToPadding="false"
Now, Your Recyclerview looks like this,
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvQuotes"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="#dimen/_10sdp"
android:layout_marginEnd="#dimen/_10sdp"
android:background="#color/white"
android:paddingBottom="?attr/actionBarSize"
android:paddingTop="#dimen/_10sdp"
android:clipChildren="false"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listItem="#layout/item_dessert"
android:clipToPadding="false"/>
Easiest but not the best solution. Still works;
Return +1 in the getItemCount() method of your RecyclerView.Adapter implementation and wrap your code in onBindViewHolder method override with a try-catch block.
For others.Disabling nested scrolling in recyclerview also causes this problem in CoordinatorLayout with scrollable toolbar or tablayout. Because when you scroll recyclerview, toolbar or tablayout doesn't scroll.
don't align recyclerview with respect to any view.. simply make it match parent and provide margin from top....this worked for me
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerViewAddresses"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:layout_marginTop="#dimen/dimen_120dp"
/>

Categories

Resources