user2708461
user2708461

Reputation: 25

android activity admob banner overlaps

i'm trying to add admob to the main activity of my app, but the banner always overlaps.

how i can make a room for it in the app?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00BFFF"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

     <com.google.ads.AdView android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adUnitId="ca-app-pub-xxxxxxxxxxxxxx/xxxxxxxxxx"
        ads:adSize="BANNER"
        ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
        ads:loadAdOnCreate="true"/>

    <TextView
        android:id="@+id/txt_stupnjevi"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/txt_grad"
        android:layout_below="@+id/txt_grad"
        android:layout_marginTop="5dp"
        android:textColor="#FFF"
        android:textSize="40sp" />

    <ImageView
        android:id="@+id/img_glavna"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/linearLayout1"
        android:layout_below="@+id/txt_stupnjevi"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:adjustViewBounds="true"
        android:src="@drawable/img01d" />

    <TextView
        android:id="@+id/txt_grad"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/img_glavna"
        android:layout_alignParentTop="true"
        android:textColor="#FFF"
        android:textSize="35sp" />

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:indeterminate="true"
        android:visibility="gone" />

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:baselineAligned="false"
        android:weightSum="3" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/txt_dan1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:maxLength="3"
                android:paddingTop="10dp"
                android:textColor="#FFF"
                android:textSize="20sp" />

            <ImageView
                android:id="@+id/img_dan1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:src="@drawable/img01n" />

            <TextView
                android:id="@+id/txt_stupnjevi1"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_gravity="center_horizontal"
                android:layout_weight="1"
                android:paddingBottom="10dp"
                android:textColor="#FFF"
                android:textSize="18sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/txt_dan2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:maxLength="3"
                android:paddingTop="10dp"
                android:textColor="#FFF"
                android:textSize="20sp" />

            <ImageView
                android:id="@+id/img_dan2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:src="@drawable/img11d" />

            <TextView
                android:id="@+id/txt_stupnjevi2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_weight="1"
                android:textColor="#FFF"
                android:textSize="18sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/txt_dan3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:maxLength="3"
                android:paddingTop="10dp"
                android:textColor="#FFF"
                android:textSize="20sp" />

            <ImageView
                android:id="@+id/img_dan3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:src="@drawable/img13n" />

            <TextView
                android:id="@+id/txt_stupnjevi3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_weight="1"
                android:textColor="#FFF"
                android:textSize="18sp" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/txt_stupnjevi"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/txt_grad"
        android:layout_marginRight="16dp"
        android:orientation="vertical"
        android:weightSum="3" >

        <TextView
            android:id="@+id/txt_tlak"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_weight="1"
            android:drawablePadding="10dip"
            android:drawableRight="@drawable/e2"
            android:gravity="center_vertical|center_horizontal"
            android:textColor="#FFF"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/txt_vlaznost"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_weight="1"
            android:drawablePadding="10dip"
            android:drawableRight="@drawable/d1"
            android:gravity="center_vertical|center_horizontal"
            android:textColor="#FFF"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/txt_brzina"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_weight="1"
            android:drawablePadding="10dip"
            android:drawableRight="@drawable/wind"
            android:gravity="center_vertical|center_horizontal"
            android:textColor="#FFF"
            android:textSize="18sp" />

    </LinearLayout>

    <TextView
        android:id="@+id/txt_stanje"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/linearLayout1"
        android:layout_centerHorizontal="true"
        android:paddingTop="10dp"
        android:layout_marginBottom="10dp"
        android:textColor="#FFF"
        android:textSize="18sp" />


</RelativeLayout>

sometimes I also have these warnings, I can figure out why they show up those variables are used! how I can fix them?

The value of the local variable mapEntry is not used MainActivity.java /SpringWeather/src/com/spring/weather line 320 Java Problem

The value of the local variable mapEntry is not used MainActivity.java /SpringWeather/src/com/spring/weather line 291 Java Problem

The import android.database.DatabaseUtils is never used DatabaseHandler.java /SpringWeather/src/com/spring/weather line 15 Java Problem

The value of the local variable mapEntry is not used MainActivity.java /SpringWeather/src/com/spring/weather line 356 Java Problem

The value of the local variable mapEntry is not used MainActivity.java /SpringWeather/src/com/spring/weather line 339 Java Problem

Thank you!!

Upvotes: 0

Views: 1555

Answers (1)

Yjay
Yjay

Reputation: 2737

The simplest way to get the admob banner not to overlap the rest of your layout would be to wrap your RelativeLayout in a LinearLayout, having the AdView and your RelativeLayout as it's children.

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.google.ads.AdView android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        ads:adUnitId="ca-app-pub-xxxxxxxxxxxxxx/xxxxxxxxxx"
        ads:adSize="BANNER"
        ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
        ads:loadAdOnCreate="true"/>

    <RelativeLayout
        android:id="@+id/RelativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#00BFFF"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity">

    ...the rest of your RelativeLayout, aside from the AdView...

    </RelativeLayout>

</LinearLayout>

Upvotes: 1

Related Questions