LearningBasics
LearningBasics

Reputation: 664

Android:Place Ad at bottom of screen

I want to place ad banner at bottom of screen. I have written the following code which has one bug that whenever the listview content is too large when ad overrides the content and last element of listview is never visible . How can I code so that whenever the ads are not visible(because of any reason) then listview should occupy the whole screen and whenever ads are visible they should not override the last element of list view.

<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>

Upvotes: 3

Views: 523

Answers (4)

Crazy Coder
Crazy Coder

Reputation: 508

<?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>

Upvotes: 0

MUHAMMAD WASIM
MUHAMMAD WASIM

Reputation: 191

You may set"layout_above" as "startAppBanner" hopefully will with achieve that

Upvotes: 1

Abdul Mohsin
Abdul Mohsin

Reputation: 1435

Try Using this code

    <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>

Upvotes: 2

Nitesh
Nitesh

Reputation: 3903

in your linear Layout add the following

android:layout_above="@+id/startAppBanner"

It will work for sure.

Upvotes: 3

Related Questions