I am working on android project and I am having a problem getting an advert to be shown at the bottom of the screen underneath a listview without causing any overlapping.
At the moment, if there is a large number of items within the list view causing scrolling, an advert is supposed to show underneath the list view but at the moment the advert is sitting on top of the list view, therefore, the user can't see what's at the bottom of the list view.
Below is the copy of my XML layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@color/black"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="@+id/password_noRecords"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:text="There are currently\nno saved logins"
android:textSize="20dp"
android:textStyle="bold|italic"/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
<Button android:id="@+id/password_clearSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/password_clear_search"
android:layout_alignParentBottom="true"
android:visibility="gone"/>
</LinearLayout>
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
ads:adUnitId="a14d6125d95c70b"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, 015d1884222bfe01"/>
</RelativeLayout>
I've many different ways, having it all inside the relative layout instead of having another linear layout, not having align parent bottom = true but then it sits at the top of the list view overlapping whatever is at the top of the list view.
Thanks for any help you can provide.
You can fix this by using only a LinearLayout
as the base (get rid of the RelativeLayout
) and using the android:layout_weight
property on your ListView
. Example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView android:id="@+id/password_noRecords"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:text="There are currently\nno saved logins"
android:textSize="20dp"
android:textStyle="bold|italic"/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button android:id="@+id/password_clearSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/password_clear_search"
android:layout_alignParentBottom="true"
android:visibility="gone"/>
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
ads:adUnitId="a14d6125d95c70b"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, 015d1884222bfe01"/>
</LinearLayout>
Note that the ListView
has android:layout_height="0dp"
and android:layout_weight="1"
. This tells it to expand to fill any space left over after placing the other elements in the LinearLayout
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With