好吧,AdMob 的情况真的很奇怪。我想将广告放在底部 我有一个 LinearLayout。当我这样做时,它永远不会出现。当我把它放在上面时,它会完美地显示出来。不确定这里的交易是什么是我的代码。我确实在 LogCat 中收到一条警告,上面写着“没有足够的空间来显示广告!想要 <480,75> 有:<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
最佳答案
我的猜测是您的 ListView 填满了屏幕并且将 adview 向下推。为 ListView 尝试此 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>
这将只为 ListView 提供 ImageView 和广告 View 占有份额后可用的空间。
关于Android AdMob 未在底部显示 LinearLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5878283/