Pergunta

I Want to load Google Ads in in AdView in Landscape mode. The ads are loading in Portrait mode but it is not loading in Landscape mode. Please Help

Here is my code for xml:

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

     <WebView 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/web1"
    android:layout_weight="1"
    />

 <com.google.ads.AdView
    android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="fill_parent"
                     ads:adUnitId="a151c14ed73ec5f"
                     ads:adSize="SMART_BANNER"
                     ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
                     android:gravity="center"     
                     ads:loadAdOnCreate="true"
                     android:layout_weight="9" />


</LinearLayout>

And This code is written in Java:

AdView adView = (AdView)this.findViewById(R.id.adView);
    adView.loadAd(new AdRequest());

Please Reply!

AdView is Showing but ads arw not shown in AdView.

Foi útil?

Solução 2

you should check the error log may be your adview is not getting proper space required for it..

Outras dicas

You're using all your space for your webview:

android:layout_width="fill_parent"
android:layout_height="fill_parent"

Use a RelativeLayout instead, and put the WebView "above" the AdView.

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


<WebView 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/web1"
    android:layout_above="@id/adView" />

<com.google.ads.AdView
    android:id="@+id/adView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    ads:adUnitId="a151c14ed73ec5f"
    ads:adSize="SMART_BANNER"
    ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
    android:gravity="center"     
    ads:loadAdOnCreate="true"
    android:layout_alignParentBottom="true" />

</RelativeLayout>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top