Admob:adview xml来自哪里?

时间:2013-01-08 07:10:05

标签: android admob

我已经按照一些教程/ stackoverflow线程来学习如何在我的UI底部添加Admob横幅。

我已将adMob sdk添加到lib中,将以下内容添加到我要在其中展示广告的用户界面的XML

<RelativeLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"     
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="#000000">      


<com.google.ads.AdView 
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:id="@+id/adMob"
  android:layout_alignParentBottom="true"
  ads:adUnitId="YOUR AdMob publisher ID"
  ads:adSize="BANNER"/> 

然后我将以下内容添加到此UI的java代码中

AdView adview = (AdView)findViewById(R.id.adView);  
AdRequest re = new AdRequest();  
re.setTesting(true);  
adview.loadAd(re); 

我遇到的问题是我没有名为"adView"的xml。我已经尝试了几个不同版本的Java代码(每个教程都有点不同),但都会导致类似的java错误。我错过了什么?

3 个答案:

答案 0 :(得分:2)

您还没有R.id.adView(至少在您粘贴的代码中),您必须使用R.id.adMob,因为这是视图的ID。 您必须将其添加到布局文件中:

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

答案 1 :(得分:1)

您缺少包含adView.please添加的Admob库。

Here是如何将Admob添加到您的应用的完整教程。

希望它会有所帮助。

答案 2 :(得分:0)

如果您在build.gradle中使用productFlavors,请确保在productFlavors块中添加“com.google.android.gms:play-services-ads:7.5.0”依赖项,而不是通用依赖项块。

 productFlavors {
      free {
          ...
          dependencies {
              compile 'com.google.android.gms:play-services-ads:7.5.0'
          }
      }

      full {
          ...
      }
    }