Question

I am trying to imlpement AdMob into an app (worked previously when using google maps), but now when I view my app in the graphic layout on eclipse everything appears fine. My AdMob banner is at the bottom with Ads by Google in it, so I know it works, but when I load the app onto a real device (Galaxy S4) it doesn't show. My logcat say Ads not showing not refreshing ad, but no other errors I'd expect to see i.e. No space for ads etc

Here is my layout file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/relativelayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    tools:context=".MainActivity" >

    <EditText
        android:id="@+id/txtText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="29dp"
        android:alpha="1"
        android:ems="10"
        android:inputType="text" />

    <Button
        android:id="@+id/btnSpeak"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txtText"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="62dp"
        android:text="@string/btnValue" />

   <Button
        android:id="@+id/btnClear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnSpeak"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/btnClear" />  

   <RelativeLayout
       android:id="@+id/bannerlayout"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:gravity="top" >

<com.google.android.gms.ads.AdView  
    android:id="@+id/adView"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="XXXXXXXX/XXXXXXX"
    android:layout_alignParentBottom="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    />

And my class file onCreate code:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        adView = new AdView(this);
        adView.setAdSize(AdSize.SMART_BANNER);
        adView.setAdUnitId(AD_UNIT_ID);

        RelativeLayout layout = (RelativeLayout) findViewById(R.id.bannerlayout);
        layout.addView(adView);

        AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice("XXXXXXXXXXXXXXXXXXXX")
        .build();
        adView.loadAd(adRequest);

I just can't understand how The Eclipse Graphic Layout viewer shows everything fine but it doesn't show on my phone and the Logcat just tells me the ad is not showing with no other information?

Any Ideas?

EDIT: My banner is now showing, but it is showing at the top, even though it is supposed to be at the bottom?

Was it helpful?

Solution

To answer your edit. Since you're adding the adview to the relative layout with in the relative layout with a gravity set to top, it's doing just that. Try setting:

<RelativeLayout
   android:id="@+id/bannerlayout"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:gravity="bottom" >

OTHER TIPS

In "RelativeLayout layout = (RelativeLayout) findViewById(R.id.bannerlayout);" Is the banner layout is the layout of the activity on which we are coding or that a new xml?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top