Android AdMob未在底部显示LinearLayout

时间:2011-05-04 03:47:06

标签: android admob android-linearlayout adview

AdMob确实很奇怪。我想将广告放在底部,我有一个LinearLayout。当我这样做时,它永远不会出现。当我把它放在上面时,它完美地显示出来。不确定这里的交易是我的代码。我在LogCat中收到一条警告:“没有足够的空间显示广告!想要< 480,75> Has:< 480,0>”

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

2 个答案:

答案 0 :(得分:17)

我的猜测是您的列表视图填满了屏幕,并且正在推动广告视图。尝试使用此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>

这将为列表视图提供图片视图和广告视图声明其共享后可用的尽可能多的空间。

答案 1 :(得分:1)

这可能也有帮助...... Admob ads not showing - Android

正如泰德所说,列表视图可能会占用所有可用的房地产。即使使用wrap_content,如果在adView填充之前列表中包含大量数据,adView也无法展开和放置广告。

除非你做我做的事情,并且硬编码它的高度大约为50dp。不是很优雅,但仍然有效。

相关问题