Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to add empty view below Recyclerview

I was trying my hand with recyclerview and floating action button for an app. The problem I encountered is that the floating action button hinders with the buttons in recyclerview. I looked up how the android apps such as phone app(one where you have contacts displayed in gridvew) are designed to deal with this, I see that there is empty space left in the bottom which gives space between recyclerview and floating action button, user just needs to scroll to the bottom to avoid the overlap. I tried to add a view after recyclerview but not its not getting displayed, also this view should move along with the recyclerview rows. What am I missing to show a view in the end of the recyclerview. My layout file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"                 android:layout_width="match_parent"                 android:layout_height="match_parent"                 android:background="#6fbababa">      <android.support.v7.widget.RecyclerView         android:id="@+id/my_recycler_view"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:scrollbars="vertical"/>      <ImageButton         android:id="@+id/button_floating_action"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignParentRight="true"         android:layout_alignParentEnd="true"         android:src="@drawable/ic_fab"         android:background="@null"         android:layout_alignParentBottom="true"         android:layout_marginBottom="12dp"         android:layout_marginEnd="12dp"         android:layout_marginRight="12dp"         android:elevation="2dp"/>      <View         android:layout_width="match_parent"         android:layout_height="30dp"         android:layout_below="@id/my_recycler_view"         android:background="@color/white"/>  </RelativeLayout> 

enter image description here

Update: Modified the layout code to make it work.

<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"/> 
like image 890
Psypher Avatar asked Jan 04 '15 17:01

Psypher


People also ask

Why does a RecyclerView need an adapter?

RecyclerView. Adapter base class for presenting paged data from PagingData s in a RecyclerView . Adapters provide a binding from an app-specific data set to views that are displayed within a RecyclerView . A class that extends ViewHolder that will be used by the adapter.


1 Answers

Add bottom padding to the RecyclerView. Also, don't use android:layout_height="wrap_content" unless you've overridden onMeasure in the layout manager. Current layout managers do not yet support wrap content.

Add the attribute android:clipToPadding="false" to achieve the goal. As mentioned in comments.

like image 149
yigit Avatar answered Sep 20 '22 11:09

yigit