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.
Related
I am trying to achieve a layout shown in the image.
So I would like to have two views that pin on top of the screen after the users scrolls to a certain point. Other views should collapse until they are fully hidden (except for View 3 which is basically the main view of the layout. So far I have tried a few approaches.
One, that kinda works, is to use the collapsing toolbar with Pinnable View 1 and Pinnable View 2 anchored to other views (I attached the snippet of the code so you know what I managed to achieve). The problem with this approach is that, because these pinnable views are not inside a nestedScrollView, it is impossible to scroll when user starts the scroll from these two views.
So my question is, is that possible to achieve the desired effect using my current approach or is there a way to do it differently?
<?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">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/app_bar_layout_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#null">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<View
android:id="#+id/view_1"
android:layout_width="match_parent"
android:layout_marginBottom="32dp"
android:layout_height="200dp"
android:background="#0071BD"
app:layout_collapseMode="parallax">
</View>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_marginTop="32dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".ScrollingActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="#+id/view_2"
android:layout_width="wrap_content"
android:background="#5495BD"
android:layout_height="300dp"/>
<View
android:id="#+id/pinnable_view_2_anchor_view"
android:layout_width="match_parent"
android:layout_height="41dp"
android:background="#null" />
<View
android:id="#+id/view_3"
android:layout_width="match_parent"
android:background="#57B1BC"
android:layout_height="1000dp" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<View
android:id="#+id/pinnable_view_1"
android:layout_width="match_parent"
android:layout_height="64dp"
android:background="#00015E"
android:nestedScrollingEnabled="true"
app:layout_anchor="#id/app_bar_layout_view"
app:layout_anchorGravity="bottom">
</View>
<View
android:id="#+id/pinnable_view_2"
android:layout_width="match_parent"
android:background="#000002"
android:layout_height="40dp"
android:layout_marginTop="64dp"
app:layout_anchor="#id/pinnable_view_2_anchor_view"
app:layout_anchorGravity="center">
</View>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
maybe it's too late, anyway, check code from here https://github.com/Y-E-P/DoubleCollapsingToolbar, maybe it will helps other developers, who faced with the same problem. I've prepared two example how to use it, free to use this code in your projects. Here is result below.
Enjoy!
As we can see from the below sample, on changing the visibility of the view from gone to visible and vice versa, the appbar automatically expands and scrim drawn is shown as well.
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/crl_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:fillViewport="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/abl_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="#drawable/shape_rectangle_grdient_red_yellow"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="parallax">
<FrameLayout
android:id="#+id/fl_class"
android:layout_width="match_parent"
android:layout_height="#dimen/d_280dp"
android:background="#color/colorPlaceholderBg">
<ImageView
android:id="#+id/iv_class"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#color/colorPlaceholderBg" />
<ProgressBar
android:id="#+id/pb_dp_progress"
android:layout_width="#dimen/d_20dp"
android:layout_height="#dimen/d_20dp"
android:layout_gravity="center"
android:visibility="visible" />
</FrameLayout>
<RelativeLayout
android:id="#+id/rl_toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbar_default_height"
android:background="#drawable/shape_rectangle_transparent_grey_gradient">
<ImageView
android:id="#+id/iv_back"
... />
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/tl_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:minHeight="#dimen/toolbar_default_height"
android:visibility="visible"
app:contentInsetStart="#dimen/d_0dp"
app:layout_collapseMode="pin">
<include layout="#layout/view_toolbar" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/fragment_class_details_content" />
</android.support.design.widget.CoordinatorLayout>
This the code for the outer layout. As can be seen from the above layout that the pattern is mostly standard. I have tried replicating the bug in new sample but of no use. The initial problem seem to be changing the height of nested scroll view on runtime seems to be the problem but that is not the case. I tried to setExpand(false) on the click of the button but that is not working as well.
<img src="https://i.imgur.com/YGTT3oL.gif" title="source: imgur.com" />
Link to demo gif is here: https://i.imgur.com/YGTT3oL.gif
I bet the problem is caused by app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
You have to define the behavior you want when scrolling, check out this article: https://medium.com/martinomburajr/android-design-collapsing-toolbar-scrollflags-e1d8a05dcb02
Since I dont know what behaviour do you want, read the article and choose yourself. Hiding and showing the view is triggering those flags.
In your #layout/fragment_class_details_content check if
app:layout_behavior="#string/appbar_scrolling_view_behavior"
is present in the parent layout.
Also change app:layout_scrollFlags="scroll|exitUntilCollapsed|snap" to
app:layout_scrollFlags="scroll|exitUntilCollapsed"
Add this attribute to the CollapsingToolbarLayout
app:toolbarId="#+id/tl_toolbar"
Add this attribute to Toolbar:
app:popupTheme="#style/AppTheme.PopupOverlay"
Extract your gone/visible layout from android.support.design.widget.CollapsingToolbarLayout.
Too much nesting you did so avoid nesting and Use constraint layout
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.
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.
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"
/>