Admob广告未展示 - Android

时间:2010-09-01 08:48:50

标签: android webview admob

我的广告根本没有显示,我想我已经正确地遵循了文档,但它们仍然无法显示。该程序基本上是一个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>

3 个答案:

答案 0 :(得分:6)

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

LinearLayout将在先来先服务规则上分配空间。如果第一个视图占用了所有空间,则第二个视图将不会获得任何空间..

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

答案 1 :(得分:1)

我有同样的问题,我这样解决了: 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>

答案 2 :(得分:0)

<?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>