2014-01-26 48 views
0

基於什麼documentation says,我加的AdView到我的XML文件:Android,爲什麼AdView不顯示任何內容?

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v4.view.ViewPager 
      android:id="@+id/viewPager" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

    <com.google.android.gms.ads.AdView 
      android:id="@+id/adView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      ads:adUnitId="@string/api_key_admob" 
      ads:adSize="BANNER"/> 

</LinearLayout> 

而且這是我添加到我的行動的方法:

private void displayAdmob() { 
     AdView adView = (AdView)this.findViewById(R.id.adView); 
     AdRequest adRequest = new AdRequest.Builder().build(); 
     adView.loadAd(adRequest); 
    } 

,我已經添加了這些行代碼到清單文件中:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
      package="mobilesoft.asia.malaysia_directory" 
      android:versionCode="10" 
      android:versionName="2.0"> 

    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="15"/> 

    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 

    <application 
      android:label="@string/app_name" 
      android:icon="@drawable/ic_launcher" 
      android:allowBackup="true" 
      android:theme = "@style/Theme.Example"> 

     <meta-data 
       android:name="com.google.android.gms.version" 
       android:value="@integer/google_play_services_version"/> 
     <activity 
       android:name="com.google.android.gms.ads.AdActivity" 
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> 

... 

    </application> 
</manifest> 

當我運行應用程序時,AdView不顯示。我希望看到它下面我的查看傳呼機,但沒有AdView。我很懷疑ads:adUnitId="MY_AD_UNIT_ID"。當我創建我的Android應用程序時,AdMob頁面中沒有AD_UNIT_ID。我使用AdMob提供的「發佈商ID」,並將其分配給ads:adUnitId="Publisher_ID"。你認爲這是我的問題嗎?

第二件事,我沒有使用AdMob SDK。我已將「google_play_services_lib」添加到我的項目中,並使用此庫代替AdMob SDK。

任何建議,將不勝感激。謝謝

回答

0

狗屎,我的XML設計有問題。

我改變了看法尋呼機的設計下面的代碼和AdView的正常工作,在屏幕的底部:

<android.support.v4.view.ViewPager 
      android:id="@+id/viewPager" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1"/> 
相關問題