【问题标题】:Admob ads not showing - AndroidAdmob 广告未展示 - Android
【发布时间】:2010-09-01 08:48:49
【问题描述】:

我的广告根本没有展示,我认为我正确地遵循了文档,但它们仍然不会展示。该程序基本上是一个 webview,我希望广告显示在底部。

这是我的布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:myapp="http://schemas.android.com/apk/res/man.utd.headlines"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">
   <WebView
      android:id="@+id/webview"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" />
   <com.admob.android.ads.AdView
      android:id="@+id/ad"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      myapp:backgroundColor="#000000"
      myapp:primaryTextColor="#FFFFFF"
      myapp:secondaryTextColor="#CCCCCC" />
</LinearLayout>

有什么想法吗?

编辑:这是我现在拥有的,但似乎仍然不太正确:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/man.utd.headlines"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" >
<com.admob.android.ads.AdView 
    android:id="@+id/ad"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    myapp:backgroundColor="#000000"
    myapp:primaryTextColor="#FFFFFF"
    myapp:secondaryTextColor="#CCCCCC" />
<WebView
    android:id="@+id/webview"
    android:layout_above="@id/ad"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
</RelativeLayout>

【问题讨论】:

  • 您的布局看起来不正确。你的 webview 占据了整个屏幕。尝试切换 webview 和 adview 并将 adview 的高度更改为 wrap_content 而不是 fill_parent。
  • Admob 中的一个错误可能是!

标签: android webview admob


【解决方案1】:

您的问题是 WebView 将占据屏幕上的所有空间,并且没有空间用于广告。

LinearLayout 将按照先到先得的规则分配空间。如果第一个视图占用了所有空间,则第二个视图将不会获得任何空间..

我会使用RelativeLayout 并首先使用layout_alignParentBottom 属性添加添加,然后使用layout_above="id for the adds" 添加webview。这将确保添加始终位于屏幕底部,即使 webview 目前不会占用所有空间并且 webview 将始终位于添加上方。

【讨论】:

  • 谢谢您 - 我似乎在正确的轨道上,但我仍然没有看到广告 - 我需要更改填充父项吗?我仍在尝试了解 Android 布局,但感谢您迄今为止的大力帮助。
  • 广告应该是 wrap_content 作为高度和 fill_parent 作为我假设的宽度。 Webview 可以保持 fill_parent。这应该会导致添加尽可能大的布局,并且 web 视图尽可能大。
  • 嗯,它似乎仍然无法正常工作 - 只是为了确认 - 这一切看起来都正确吗? (见更新)
  • 应该没问题。屏幕底部是否有黑条,还是 webview 占用了所有空间?
  • Webview 占用了所有空间。在我的 admob 帐户中,我可以看到广告有请求,但它们只是没有显示。 :(
【解决方案2】:

我遇到了同样的问题,我是这样解决的: LinearLayout 作为主布局,在它里面有linearLayout(用于广告)和一个webview,在广告的linearlayout 上设置wrap_content,所以,它首先会显示一个广告,然后屏幕的其余部分将是webview。 我的例子:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
  <LinearLayout 
 android:id="@+id/addmob"
 xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
></LinearLayout>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>



</LinearLayout>

【讨论】:

    【解决方案3】:
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:layout_width="fill_parent" android:id="@+id/rltvLayout1"
        android:layout_height="fill_parent">
        <LinearLayout android:id="@+id/linearLayoutwebview"
            android:layout_height="wrap_content" android:layout_width="wrap_content"
            android:orientation="vertical">
            <WebView android:id="@+id/webView1"
                android:layout_width="fill_parent" android:layout_height="fill_parent"
                android:fitsSystemWindows="true" />
        </LinearLayout>
        <LinearLayout android:layout_width="fill_parent"
            android:id="@+id/ad_layout" android:layout_height="wrap_content"
            android:gravity="bottom" android:layout_alignParentBottom="true"
            android:layout_alignBottom="@+id/home_layout">
            <com.google.ads.AdView android:layout_width="wrap_content"
                android:layout_height="wrap_content" ads:adUnitId="put here your ID"
                ads:adSize="BANNER" android:id="@+id/adView" ads:refreshInterval="60" />
    
        </LinearLayout>
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-06
      • 1970-01-01
      • 2016-10-24
      • 1970-01-01
      相关资源
      最近更新 更多