我按照官方链接中的步骤操作,我找不到问题所在。我从以下网址下载了lib:https://developers.google.com/mobile-ads-sdk/download#downloadandroid 这是我的代码: 在MainActivity中,我添加:
adView = (AdView) findViewById(R.id.ad);
AdRequest adRequest = new AdRequest();
adView.loadAd(adRequest);
在清单中:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
和xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/lytMain"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/libs/com.google.ads"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-xxxxxxxx/xxxxxx"
ads:testDevices="TEST_EMULATOR"
ads:loadAdOnCreate="true" >
</com.google.ads.AdView>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:gravity="center"
>
<TextView
android:id="@+id/cargando"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cargando resultados..."
android:textColor="@android:color/black"
android:textSize="20sp" />
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Small.Inverse"
android:layout_marginRight="5dp" />
<Button
android:id="@+id/button"
android:visibility="invisible"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Ver resultados" />
</LinearLayout>
</LinearLayout>
答案 0 :(得分:1)
在最新的SDK中:
XML:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxxxxxxxxxxxxx" />
代码:
adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
答案 1 :(得分:0)
尝试编辑并使用。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res/com.jms.AdmobExample"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res/com.jms.AdmobExample"
android:id="@+id/add_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ns:adSize="BANNER"
ns:adUnitId="a14f1d807e488dd" >
</com.google.ads.AdView>
</Linearlayout>