rootpanthera
rootpanthera

Reputation: 2771

Ads covering bottom of layout Android

I have a simple layout. But I can't make it work along with an AD which I want to put in the bottom. Here are 2 screenshots with and without an AD.

Without AD

enter image description here

With AD

enter image description here

As you can see the AD when it's loaded, it covers both buttons ( which are in relative layout ). How can I make it this right, so when AD is loaded, my relative layout "bumps" above the ad ? Here is my XML.

    <?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:app="http://schemas.android.com/apk/res/example.com">



    <com.example.touch.TouchImageView android:id="@+id/mytouchview"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="5dp"
        android:layout_above="@+id/relat"
        />




        <RelativeLayout
            android:id="@+id/relat"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
             >

             <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dp" android:layout_alignParentLeft="true" 
            android:background="@null" android:src="@drawable/previous"  android:id="@+id/previous"/>

             <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="20sp" android:text="2/15"
         android:id="@+id/memeNumber" android:layout_centerInParent="true" android:layout_margin="5dp"/>


        <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dp" android:layout_alignParentRight="true" 
             android:background="@null"  android:src="@drawable/next" android:id="@+id/next"/>


 </RelativeLayout>



    <com.csjy.sfwn148282.AdView
xmlns:ap="http://schemas.android.com/apk/res-auto"
android:id="@+id/myAdView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ap:animation="fade"
ap:placementType="interstitial"
ap:banner_type="inappad"
ap:test_mode="true"
ap:canShowMR="false"
android:layout_alignParentBottom="true"


/>

</RelativeLayout>

EDIT:

I did like @Szymon adviced me, but the problem I'm facing now is that layout is positioned like this , until ad loads. After that, it works like it should. How to fix that?

enter image description here

Upvotes: 1

Views: 137

Answers (1)

Szymon
Szymon

Reputation: 43023

This will work for you. Note that you should use @+id only once for each variable you declare (even if you declare it in some other place than the actual element). In the code below, it is declared in android:layout_above and only used as @id in the actual element declaration.

<?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:app="http://schemas.android.com/apk/res/example.com">



    <com.example.touch.TouchImageView android:id="@+id/mytouchview"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="5dp"
        android:layout_above="@+id/relat"
        />

        <RelativeLayout
            android:id="@id/relat"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:layout_above="@+id/myAdView"
             >

             <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dp" android:layout_alignParentLeft="true" 
            android:background="@null" android:src="@drawable/previous"  android:id="@+id/previous"/>

             <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="20sp" android:text="2/15"
                android:id="@+id/memeNumber" android:layout_centerInParent="true" android:layout_margin="5dp"/>


            <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dp" android:layout_alignParentRight="true" 
             android:background="@null"  android:src="@drawable/next" android:id="@+id/next"/>


        </RelativeLayout>



    <com.csjy.sfwn148282.AdView
        xmlns:ap="http://schemas.android.com/apk/res-auto"
        android:id="@id/myAdView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ap:animation="fade"
        ap:placementType="interstitial"
        ap:banner_type="inappad"
        ap:test_mode="true"
        ap:canShowMR="false"
        android:layout_alignParentBottom="true"
    />

</RelativeLayout>

Upvotes: 2

Related Questions