简体   繁体   中英

Admob banner not appearing when placed in relative layout

I want to make the ad appear on the top left hand portion of the screen in the preview it is located where it is supposed to be it just never shows up in the app when I run it. Does anyone know why this is?

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_img);
    AdView adView = (AdView)this.findViewById(R.id.adView);
    adView.loadAd(new AdRequest());    
}

<RelativeLayout android:id="@+id/RelativeLayout01"
                android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:layout_weight="2"
                xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        >


    <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/imageView"
            android:layout_gravity="center"
            android:scaleType="centerCrop"
            android:layout_alignBottom="@+id/imageButton4"
            android:layout_alignParentLeft="true"/>

    <com.google.ads.AdView android:id="@+id/adView"
                           android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           ads:adUnitId="xxxxxxx"
                           ads:adSize="BANNER"
                           ads:loadAdOnCreate="true"
                           android:layout_alignParentTop="true" android:layout_alignParentLeft="true"
                           android:layout_toLeftOf="@+id/imageButton"/>
    <ImageButton
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:scaleType="fitCenter"
            android:onClick="exit"
            android:background="@null"
            android:id="@+id/imageButton"
            android:src="@drawable/deletebuttonbar2"
            android:layout_alignParentTop="true" android:layout_alignParentRight="true"/>
    <ImageButton
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:scaleType="fitCenter"
            android:onClick="save"
            android:background="@null"
            android:src="@drawable/savebuttonbar3"
            android:id="@+id/imageButton2"
            android:layout_alignBottom="@+id/imageButton4" android:layout_toLeftOf="@+id/imageButton4"/>



    <ImageButton

            android:layout_width="72dp"
            android:layout_height="72dp"
            android:onClick="send"
            android:scaleType="fitCenter"
            android:background="@null"
            android:src="@drawable/share"
            android:id="@+id/imageButton3"
            android:layout_alignParentBottom="true" android:layout_toRightOf="@+id/imageButton4"/><![CDATA[

                  android:layout_height="wrap_content" android:layout_toLeftOf="@+id/imageButton">
        ]]>
    <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:id="@+id/imageButton4"
            android:onClick="filter"
            android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:paddingRight="10dp"/>

</RelativeLayout>

The ad requires 320dp width to show. You have the ad aligned to left of a 70dp width image, so it probably doesn't have enough space to show. Check your LogCat output for this error, and fix your layout to give the ad space.

Side note - you don't need to call adView.loadAd(new AdRequest()); in code because you have ads:loadAdOnCreate="true" in your XML. You're making a duplicate call - AdMob will ignore the second one if the first one hasn't finished yet.

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