2011-05-04 78 views
5

好吧AdMob真的很奇怪。我想將廣告放在底部我有一個LinearLayout。當我這樣做時,它永遠不會出現。當我把它放在上面時,它顯示完美。不知道這裏的交易是我的代碼。我得到的logcat的一個警告,說: 「沒有足夠的空間來展示廣告想< 480,75>的:< 480,0>」Android AdMob底部不顯示LinearLayout

LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/res/mypackage" 
android:id="@+id/mainmenulayout" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

    <ImageView android:id="@+id/headerpic" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:src="@drawable/header"/> 

    <ListView android:id="@android:id/list" 
    android:divider="#00000000" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:drawSelectorOnTop="false" 
    android:background="@android:color/transparent" 
    android:cacheColorHint="#00000000" 
    android:layout_alignParentTop="true"> 
    </ListView> 

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

和我的onCreate():

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.appmenu); 

    // Look up the AdView as a resource and load a request. 
    AdView adView = (AdView)this.findViewById(R.id.adView); 
    adView.loadAd(new AdRequest()); 

    String[] mainMenuList = getResources().getStringArray(R.array.mainMenuList); 
    TypedArray[] picFiles = getResources().obtainTypedArray(R.array.arrayIcon); 

    setListAdapter(new MyIconAdapter(mainMenuList, picFiles)); 

    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 

} //close onCreate 

回答

17

我的猜測是你的列表視圖填滿了屏幕並且正在推動adview。試試這個XML列表視圖:

<ListView android:id="@android:id/list" 
    android:divider="#00000000" 
    android:layout_width="fill_parent" 
    android:layout_height="0px" 
    android:layout_weight="1" 
    android:drawSelectorOnTop="false" 
    android:background="@android:color/transparent" 
    android:cacheColorHint="#00000000" 
    android:layout_alignParentTop="true"> 
    </ListView> 

這將使列表視圖只有儘可能多的房地產作爲可在圖像視圖和廣告視圖聲稱他們的份額之後。

+0

是的,這是否表示感謝,我仍然需要了解重量如何工作。似乎有點向後讓高度0,但看看重量來填補休息。真的變得惱火與android佈局...再次感謝 – JPM 2011-05-04 07:51:14

1

這可能有助於太... Admob ads not showing - Android

特德說,列表視圖,可以採取所有可用的房地產。即使使用wrap_content,如果在adView填充之前列表中填充了大量數據,adView將無法展開並放置廣告。

除非你做了我所做的並且硬編碼它的高度爲大約50dp。不是很優雅,但仍然有效。