问题
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.
回答1:
you should check the error log may be your adview is not getting proper space required for it..
回答2:
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>
来源:https://stackoverflow.com/questions/17369551/ads-are-not-loading-in-adview-in-landscape-mode-android