简体   繁体   中英

How to position admob advertisement in xml?

Here is my xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent" 
    android:layout_height="match_parent">


<com.google.android.gms.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="MY - ID"
                         ads:adSize="BANNER"
                         android:layout_alignParentBottom="true"
                         android:layout_alignParentLeft="true"


                         />



<ListView
        android:id="@+id/listView0"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" 
        android:scrollingCache="false"
         android:layout_above="@+id/adView" >

</ListView>
</RelativeLayout>

New admob advertisement does not allow

  ads:loadAdOnCreate="true" 

method to use.

i want to position my advertisement end of the page and center. Also, if i have not internet connections there is advertisement area but no advertisement.How can i fix this?

Try creating a different XML file for your google admob and include it in your main layout.

This way you can design your layout much more easier.

<include layout="@layout/admob"/>

By the way you can set the visibility of your layout either in your java code or xml if you want to hide it.

Use below code in xml :

  <RelativeLayout
        android:id="@+id/rlTop"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/rlBottom"
        android:layout_alignParentTop="true" >

              <ListView > </ListView>

</RelativeLayout>

<RelativeLayout
        android:id="@+id/rlBottom"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="center" >

  <!-- place your xml ad code here -->      

    </RelativeLayout>

You can refer above sample xml code for placing ads at bottom.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM