2011-05-04 61 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。不是很优雅,但仍然有效。