2015-07-01 58 views
-2

嗨,我想顯示在片段AD瀏覽,但我沒有得到任何結果,它只顯示空白區域,在活動的正常工作,AdView中的片段沒有顯示

的片段我寫的代碼如下:

XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/innerbg" 
    xmlns:app="http://schemas.android.com/apk/lib/com.google.ads"> 

<ListView 
    android:id="@+id/listview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:choiceMode="singleChoice" 
    android:divider="@null" 
    android:listSelector="@android:color/transparent" 
    android:layout_above="@+id/adView" 
    android:layout_alignParentTop="true"/> 

<com.google.android.gms.ads.AdView 
      xmlns:ads="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/adView" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      ads:adSize="BANNER" 
      ads:adUnitId="@string/adunit_id_home" 
      android:layout_alignParentBottom="true"/> 

</RelativeLayout> 

在片段:

AdView adViewHome = (AdView) rootView.findViewById(R.id.adViewHome); 
AdRequest adRequest = new AdRequest.Builder().build(); 
adViewHome.loadAd(adRequest); 
+0

爲什麼它下來投票?我可以知道原因嗎? –

+0

我不知道爲什麼這些人投票的問題,如果有任何問題,那麼讓我知道,以便我將來不會重複。沒有通知做倒票是不正確的方式,你必須糾正新手 –

回答

0

你的列表視圖是TA在整個屏幕上占主導地位,所以adview沒有機會展示。改變你的佈局。

<RelativeLayout 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <ListView 
     android:choiceMode="singleChoice" 
     android:divider="@null" 
     android:id="@+id/listview" 
     android:layout_alignParentTop="true" 
     android:layout_gravity="start" 
     android:layout_width="match_parent" 
     android:listSelector="@android:color/transparent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/adView" /> 

    <com.google.android.gms.ads.AdView  
     xmlns:ads="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/adView" 
     android:layout_alignParentBottom="true" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     ads:loadAdOnCreate="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="@string/adunit_id_home" /> 
</RelativeLayout> 

在片段:

AdView adViewHome = (AdView) rootView.findViewById(R.id.adViewHome); 
AdRequest adRequest = new AdRequest.Builder().build(); 
adRequest.setTesting(true); 
adViewHome.loadAd(adRequest); 
+0

請檢查我編輯的問題。 –

+0

你有沒有在清單中設置你的權限? – Eoin

+0

你嘗試設置列表視圖來包裝內容? – Eoin