Android AdMob 未在底部显示 LinearLayout
好吧,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
Okay really weird situation with AdMob. I want to place the ad on the bottom I have a LinearLayout. When I do it never shows up. When I place it on top it shows up perfectly. Not sure what the deal is here is my code. I do get a warning in LogCat that says "Not enough space to show ad! Wants <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>
and my 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的猜测是您的列表视图填满了屏幕并将广告视图向下推。尝试为列表视图使用此 xml:
这将只为列表视图提供图像视图和广告视图声明其份额后可用的空间。
My guess is that your list view fills the screen and is pushing the adview down. Try this xml for the list view:
This will give the list view only as much real estate as is available after the image view and ad view claim their share.
这也可能有帮助...
Admob 广告未展示 - Android
正如 Ted 所说,列表视图可能会占据所有内容可用的房地产。即使使用了wrap_content,如果在adView填充之前列表填充了大量数据,adView将无法展开并放置广告。
除非你像我一样,将它的高度硬编码到大约 50dp。不是很优雅,但仍然有效。
This might help too...
Admob ads not showing - Android
As Ted says, the list view may be taking up all available real-estate. Even with wrap_content, if the list is populated with a lot of data before the adView populates, the adView will not be able to expand and place the ad.
Unless you do what I did and hard code it's height to about 50dp. Not very elegant, but still effective.