Android 在横向模式下,广告未加载到AdView中

Android 在横向模式下,广告未加载到AdView中,android,adview,Android,Adview,我想以横向模式在AdView中加载Google广告。广告以纵向模式加载,但不是横向模式加载。请帮忙 以下是我的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="ma

我想以横向模式在AdView中加载Google广告。广告以纵向模式加载,但不是横向模式加载。请帮忙

以下是我的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>
请回复


AdView正在显示,但AdView中没有显示广告。

您应该检查错误日志,可能是您的AdView没有获得所需的适当空间。

您应该检查错误日志,可能是您的AdView没有获得所需的适当空间。

您正在将所有空间用于webview:

android:layout_width="fill_parent"
android:layout_height="fill_parent"
改为使用RelativeLayout,并将WebView置于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>

您正在将所有空间用于webview:

android:layout_width="fill_parent"
android:layout_height="fill_parent"
改为使用RelativeLayout,并将WebView置于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>



我如何知道它是否获得了适当的空间?请回答我如何知道AdView是否获得了适当的空间?然后你可以使用android:layout\u width=“fill\u parent”android:layout\u height=“wrap\u content”linearlayout layout=(linearlayout)findViewById(R.id.mainAdsLayout)进行任何线性布局;layout.addView(adview);AdRequest AdRequest=新AdRequest();addTestDevice(addRequest.LOGTAG);adview.loadAd(adrequest);但我如何将此广告放置在网络视图下方?我如何知道它是否没有获得适当的空间?请务必回答我如何知道广告是否没有获得适当的空间?然后您可以使用android:layout\u width=“fill\u parent”android:layout\u height=“wrap\u content”linearlayout layout=(linearlayout)findViewById进行任何线性布局(R.id.mainAdsLayout);layout.addView(adview);AdRequest AdRequest=new AdRequest();AdRequest.addTestDevice(AdRequest.LOGTAG);adview.loadAd(AdRequest);但我如何将此adview放置在Web视图下方?我已更改布局:是的,我复制了您的代码。adview正在显示,但广告没有显示在adview中。我只是得到一个空白adview。我认为如果您已在xml中设置了所有内容,则不需要Java代码,这可能是问题所在。请尝试删除它。然后更改
测试设备ID
使用您的实际设备id。我正在模拟器上测试它或检查logcat。在真实设备上尝试它。检查internet权限。我已更改布局:是的,我复制了您的代码。AdView正在显示,但AdView中没有显示广告。我只是得到一个空白AdView。如果您已在xml中设置了所有内容,我认为您不需要Java代码,probab这就是问题所在。请尝试删除它。然后用实际设备ID更改
测试设备ID
。我正在模拟器上测试它,或者检查日志。在真实设备上尝试。检查internet权限。