AdView attached to the bottom prevents me from seeing the last item in Recyclerview

I have a RelativeLayout in which I have a RecyclerView and a LinearLayout with an AdView inside. RecyclerView has many elements, and when I couldnโ€™t show them on the screen, I just had to scroll down to see them, but now that I added a LinearLayout attached to the bottom of the screen using the AdView inside, I scroll down and I donโ€™t I can see the last element of RecyclerView . I am attaching a LinearLayout to the bottom, but it seems to be above the RecyclerView , and I want the RecyclerView display the elements on the screen, but not behind the LinearLayout . Is it possible?

Here is my XML for the layout:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:ads="http://schemas.android.com/apk/res-auto"> <android.support.v7.widget.RecyclerView android:id="@+id/rvGeneric" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical"> </android.support.v7.widget.RecyclerView> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:gravity="center"> <com.google.android.gms.ads.AdView android:id="@+id/adViewBaseRefresh" android:layout_width="fill_parent" android:layout_height="53dp" ads:adSize="BANNER" ads:adUnitId="@string/banner_ad_unit_id" android:layout_marginBottom="3dp"> </com.google.android.gms.ads.AdView> </LinearLayout> 

+5
source share
2 answers

Relative layout requires the Relative relationships defined in XML. Since you do not have (other than aligning the linear layout at the bottom), the result is an overlap between LL and RecyclerView.

Add the line android: layout_below = "@ id / rvGeneric" to the linear layout

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:ads="http://schemas.android.com/apk/res-auto"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/ll_ad" android:layout_alignParentBottom="true" android:gravity="center"> <com.google.android.gms.ads.AdView android:id="@+id/adViewBaseRefresh" android:layout_width="fill_parent" android:layout_height="53dp" ads:adSize="BANNER" ads:adUnitId="@string/banner_ad_unit_id" android:layout_marginBottom="3dp"> </com.google.android.gms.ads.AdView> </LinearLayout> <android.support.v7.widget.RecyclerView android:id="@+id/rvGeneric" android:layout_above="@id/ll_ad" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical"/> </RelativeLayout> 
+3
source

For this, I personally used LinearLayout, as shown below:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout 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" tools:context="com.example.geoff.stackoverflowtesting.MainActivity" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/rvGeneric" android:layout_width="match_parent" android:layout_height="match_parent" android:text="TESTING2" android:background="#FFF000" android:textSize="200dp" android:scrollbars="vertical"> </TextView> </LinearLayout> </ScrollView> <TextView android:id="@+id/adViewBaseRefresh" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="TESTING" android:textSize="30dp" android:textColor="#FFF000" android:background="#000000" android:layout_marginBottom="3dp" android:layout_weight="0.1"> </TextView> </LinearLayout> 

If you especially want to use RelativeLayout, then:

 <?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" tools:context="com.gfaiers.layoutexamples.MainActivity" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/rvGeneric" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical"> </android.support.v7.widget.RecyclerView> </LinearLayout> </ScrollView> <com.google.android.gms.ads.AdView android:id="@+id/adViewBaseRefresh" android:layout_width="match_parent" android:layout_height="wrap_content" ads:adSize="BANNER" ads:adUnitId="@string/banner_ad_unit_id" android:layout_marginBottom="3dp"> </com.google.android.gms.ads.AdView> </RelativeLayout> 
0
source

All Articles