Unable to place view below RecyclerView Unable to place view below RecyclerView xml xml

Unable to place view below RecyclerView


I had a view that needed to be under a recycler view with dynamic size.meaning that the view supposes to move down as the RecyclerView grew.

my solution was to add paddingBottom to the RecyclerView and then negative marginTop in the same value to the view, it worked perfectly.

<LinearLayout    android:orientation="vertical"    android:layout_width="match_parent"    android:layout_height="match_parent">    <android.support.v7.widget.RecyclerView        android:paddingBottom="48dp"        android:layout_width="match_parent"        android:layout_height="wrap_content"        />        <TextView            android:layout_marginTop="-48dp"            android:layout_width="match_parent"            android:layout_height="wrap_content"            /></LinearLayout>


I rewrote your layout file, The recycleview is wrapped inside a linearlayout

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    xmlns:ads="http://schemas.android.com/apk/res-auto"    android:layout_width="match_parent"    android:layout_height="match_parent"><LinearLayout   android:id="@+id/wrapper"   android:layout_width="match_parent"   android:layout_height="60dp"   android:layout_alignParentTop="true"   android:layout_centerHorizontal="true"   android:layout_marginBottom="12dp"   android:orientation="vertical">   <android.support.v7.widget.RecyclerView       android:id="@+id/recycler_view"       android:layout_width="match_parent"       android:layout_height="wrap_content"       android:clipToPadding="false"       android:paddingBottom="20dp"       android:paddingLeft="@dimen/activity_horizontal_margin"       android:paddingRight="@dimen/activity_horizontal_margin"       android:paddingTop="10dp" />   </LinearLayout><com.google.android.gms.ads.AdView    android:id="@+id/adView"    android:layout_width="match_parent"    android:background="#000000"    android:layout_height="60dp"    android:layout_below="@+id/wrapper"    ads:adSize="BANNER"    ads:adUnitId="ca-app-pub-3940256099942544/6300978111"></com.google.android.gms.ads.AdView><RelativeLayout    android:id="@+id/relContainer"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_below="@+id/adView"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin">    <TableLayout        android:id="@+id/purchaseTableLayout"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingBottom="7dp"        android:paddingTop="7dp"        android:layout_alignParentTop="true"        android:stretchColumns="0,1,2">        <TableRow            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:weightSum="3">            <TextView                android:id="@+id/textView1"                android:layout_width="0dp"                android:layout_height="match_parent"                android:layout_weight="1"                android:gravity="center_vertical"                android:paddingLeft="2dp"                android:singleLine="true"                android:textColor="#000"                android:textSize="24sp"                android:textStyle="bold" />            <TextView                android:id="@+id/textView2"                android:layout_width="0dp"                android:layout_height="match_parent"                android:layout_weight="1"                android:gravity="center_vertical"                android:paddingLeft="2dp"                android:singleLine="true"                android:textColor="#000"                android:textSize="24sp"                android:textStyle="bold" />            <Spinner                android:id="@+id/typeSpinner"                style="style/Theme.Material"                android:layout_width="0dp"                android:layout_height="match_parent"                android:layout_weight="1"                android:gravity="center_vertical" />        </TableRow>    </TableLayout>    <EditText        android:id="@+id/searchEditText"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_centerHorizontal="true"        android:layout_below="@+id/purchaseTableLayout"        android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'() "        android:hint="Search"        android:imeOptions="actionDone"        android:singleLine="true" />    <TableLayout        android:id="@+id/tableLayout"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@+id/searchEditText"        android:paddingBottom="7dp"        android:paddingTop="7dp"        android:stretchColumns="0,1,2">        <TableRow            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:weightSum="3.0">            <Spinner                android:id="@+id/sortRaceSpinner"                style="style/Theme.Material"                android:paddingTop="5dp"                android:paddingBottom="10dp"                android:layout_width="0dp"                android:layout_height="match_parent"                android:layout_weight="1.0"/>            <Spinner                android:id="@+id/sortAffinitySpinner"                style="style/Theme.Material"                android:paddingTop="5dp"                android:paddingBottom="10dp"                android:layout_width="0dp"                android:layout_height="match_parent"                android:layout_weight="1.0"/>            <Spinner                android:id="@+id/sortSpinner"                style="style/Theme.Material"                android:paddingTop="5dp"                android:paddingBottom="10dp"                android:layout_width="0dp"                android:layout_height="match_parent"                android:layout_weight="1.0" />        </TableRow>    </TableLayout></RelativeLayout>

The result is as show

enter image description here

If your recycleview content will extend beyond the display height then you should consider dividing your layout into partitions with android:layout_weight.

Update

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"xmlns:ads="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"><RelativeLayout    android:id="@+id/relContainer"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_alignParentTop="true"    android:layout_centerHorizontal="true"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin">    <TableLayout        android:id="@+id/purchaseTableLayout"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingBottom="7dp"        android:paddingTop="7dp"        android:layout_alignParentTop="true"        android:stretchColumns="0,1,2">        <TableRow            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:weightSum="3">            <TextView                android:id="@+id/textView1"                android:layout_width="0dp"                android:layout_height="match_parent"                android:layout_weight="1"                android:gravity="center_vertical"                android:paddingLeft="2dp"                android:singleLine="true"                android:textColor="#000"                android:textSize="24sp"                android:textStyle="bold" />            <TextView                android:id="@+id/textView2"                android:layout_width="0dp"                android:layout_height="match_parent"                android:layout_weight="1"                android:gravity="center_vertical"                android:paddingLeft="2dp"                android:singleLine="true"                android:textColor="#000"                android:textSize="24sp"                android:textStyle="bold" />            <Spinner                android:id="@+id/typeSpinner"                style="style/Theme.Material"                android:layout_width="0dp"                android:layout_height="match_parent"                android:layout_weight="1"                android:gravity="center_vertical" />        </TableRow>    </TableLayout>    <EditText        android:id="@+id/searchEditText"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_centerHorizontal="true"        android:layout_below="@+id/purchaseTableLayout"        android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'() "        android:hint="Search"        android:imeOptions="actionDone"        android:singleLine="true" />    <TableLayout        android:id="@+id/tableLayout"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@+id/searchEditText"        android:paddingBottom="7dp"        android:paddingTop="7dp"        android:stretchColumns="0,1,2">        <TableRow            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:weightSum="3.0">            <Spinner                android:id="@+id/sortRaceSpinner"                style="style/Theme.Material"                android:paddingTop="5dp"                android:paddingBottom="10dp"                android:layout_width="0dp"                android:layout_height="match_parent"                android:layout_weight="1.0"/>            <Spinner                android:id="@+id/sortAffinitySpinner"                style="style/Theme.Material"                android:paddingTop="5dp"                android:paddingBottom="10dp"                android:layout_width="0dp"                android:layout_height="match_parent"                android:layout_weight="1.0"/>            <Spinner                android:id="@+id/sortSpinner"                style="style/Theme.Material"                android:paddingTop="5dp"                android:paddingBottom="10dp"                android:layout_width="0dp"                android:layout_height="match_parent"                android:layout_weight="1.0" />        </TableRow>    </TableLayout></RelativeLayout><LinearLayout    android:id="@+id/wrapper"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:layout_below="@+id/relContainer"    android:background="@color/colorPrimary"    android:orientation="vertical">    <android.support.v7.widget.RecyclerView        android:id="@+id/recycler_view"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:padding="10dp" /></LinearLayout><LinearLayout    android:id="@+id/wrappers"    android:layout_width="match_parent"    android:layout_height="60dp"    android:layout_alignParentBottom="true"    android:orientation="vertical">    <com.google.android.gms.ads.AdView        android:id="@+id/adView"        android:layout_width="match_parent"        android:layout_height="60dp"        android:layout_alignParentBottom="true"        android:layout_centerHorizontal="true"        ads:adSize="BANNER"        ads:adUnitId="ca-app-pub-3940256099942544/6300978111">    </com.google.android.gms.ads.AdView></LinearLayout>

enter image description here


Try adding the android:clipToPadding="false" attribute to your RecyclerView.

The official documentation says, about clipToPadding:

Sets whether this ViewGroup will clip its children to its padding and resize (but not clip) any EdgeEffect to the padded region, if padding is present.

By default, children are clipped to the padding of their parent ViewGroup. This clipping behavior is only enabled if padding is non-zero.


Your XML layout would end up being:

layout.xml

<android.support.v7.widget.RecyclerView    android:id="@+id/recycler_view"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:layout_below="@+id/relContainer"    android:background="@drawable/bordershadow2"    android:clipToPadding="false"    android:paddingBottom="20dp"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="10dp" />