Posts Tagged ‘RecyclerView’

Hello all,

After getting so many +1 over stackoverflow for my answer on the question : How to use RecyclerView inside NestedScrollView?

You can add RecyclerView without adding it into NestedScrollView. How? Here is the trick:

<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:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
 android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">

 <android.support.v7.widget.Toolbar
 android:layout_width="match_parent"
 android:layout_height="?attr/actionBarSize"
 android:background="?attr/colorPrimary"
 app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
 app:layout_behavior="@string/appbar_scrolling_view_behavior"
 android:layout_width="match_parent"
 android:layout_height="wrap_content" />
</android.support.design.widget.CoordinatorLayout>

The key thing here is :

 app:layout_behavior="@string/appbar_scrolling_view_behavior" 

Have fun! Keep Coding!

Advertisements

Now a days we are using Android Design Library to have rich look.

I’ve faced this problem while integrating RecyclerView with FAB (Floating Action Button) and I was not able to read the last line of it due to FAB was overlapping it.

I’ve tried this (Wrong assumption):


<android.support.v7.widget.RecyclerView 
android:id="@+id/my_recycler_view" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:padding_bottom="30dp"
/>

After some research found that its very easy to implement :

Method 1: Create Style

<style name="rvWithClipPadding">
<item name="android:clipToPadding">false</item>
<item name="android:paddingBottom">@dimen/margin_56dp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:scrollbars">vertical</item>
</style>

use this style in xml,

<android.support.v7.widget.RecyclerView 
android:id="@+id/my_recycler_view" 
style="@style/rvWithClipPadding"
/>

Method 2: Use attributes while creating

<android.support.v7.widget.RecyclerView 
android:id="@+id/my_recycler_view" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:clipToPadding="false" 
android:paddingBottom="30dp" 
android:scrollbars="vertical"/>