Android: Place an ad at the bottom of the screen.

I want to place an ad banner at the bottom of the screen. I wrote the following code, which has one error when whenever the contents of the list are too large, when the ad overrides the content, and the last element of the list is never displayed. How can I code so that whenever the ads are not visible (for any reason), the listview should occupy the entire screen, and whenever the ads are visible, they should not override the last element of the list.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rlLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background_img"
    tools:context="${packageName}.${activityClass}" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" >

        <ListView
            android:id="@+id/rhymesList"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:divider="@null"
            android:dividerHeight="0dp" >
        </ListView>
    </LinearLayout>

    <com.startapp.android.publish.banner.Banner
        android:id="@+id/startAppBanner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>
+4
source share
4 answers

in your line layout add the following

android:layout_above="@+id/startAppBanner"

This will work for sure.

+3
source

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/rlLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/background_img"
        tools:context="${packageName}.${activityClass}" >

        <com.startapp.android.publish.banner.Banner
            android:id="@+id/startAppBanner"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true" />

        <ListView
            android:id="@+id/rhymesList"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/startAppBanner"
            android:divider="@null"
            android:dividerHeight="0dp" >
        </ListView>



    </RelativeLayout>
+2

"layout_above" "startAppBanner", ,

+1
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rlLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/button"
    android:orientation="vertical"
    tools:context="${packageName}.${activityClass}" >

    <ListView
        android:id="@+id/rhymesList"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="0dp"
        android:divider="@null"
        android:dividerHeight="0dp" >
    </ListView>

    <com.startapp.android.publish.banner.Banner
        android:id="@+id/startAppBanner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>
0

All Articles