首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AdView nots用ExpandableListView显示

AdView nots用ExpandableListView显示
EN

Stack Overflow用户
提问于 2015-04-06 20:04:45
回答 1查看 105关注 0票数 0

我想集成一个广告与我的android应用程序。一切都很好,但是广告横幅没有显示出来!我不知道问题是什么。不管怎么说这是我的密码。对于activity_main.xml:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#f4f4f4"
android:orientation="vertical" >

<ExpandableListView
    android:id="@+id/lvExp"
     android:layout_width="match_parent"
     android:layout_height="wrap_content" />

<com.google.ads.AdView
    android:id="@+id/adView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"
    ads:adUnitId="ca-app-pub-7203358988240052/2007826925"
    ads:loadAdOnCreate="true"/>

</LinearLayout>

对于我的Main_Activity.java,我使用了:

代码语言:javascript
复制
    AdView adView = (AdView)this.findViewById(R.id.adView);
    adView.loadAd(new AdRequest());
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-06 20:13:55

您使用的是LinearLayout,它使用“长子优先”的方法。在您的布局中,您的长子是ExpandableListView ( ELV ),尽管您指定了ELV的高度应该是包装它的内容,但它仍然占用整个屏幕空间,因为在ELV中有足够的内容可以这样做。因此,您的AdsView没有显示的空间。

一种选择是使用android:layout_weight属性在不同的小部件之间分配可用的屏幕空间。因此,如果您希望您的小部件共享屏幕空间,使ELV获得屏幕的90%,而AdsView获得屏幕的10%,您可以这样做:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#f4f4f4"
android:orientation="vertical" >

<ExpandableListView
    android:id="@+id/lvExp"
     android:layout_width="match_parent"
     android:layout_height="0dip" <!-- When you are using weights, set the height to 0 as the weight will control the height -->
     android:layout_weight="90" />

<com.google.ads.AdView
    android:id="@+id/adView"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="10"
    ads:adSize="BANNER"
    ads:adUnitId="ca-app-pub-7203358988240052/2007826925"
    ads:loadAdOnCreate="true"/>

</LinearLayout>

当您使用权重时,您应该将高度设置为零,因为权重将控制垂直方向的高度。

用你想要的比例就行。你可以使用80/20或75/25或其他什么。

编辑:我从您提供的链接中下载了您的应用程序并运行了代码。我注意到的第一件事是,您的AdView确实占用了空间。这意味着布局是好的-这是因为你没有收到任何广告显示。所以我浏览了你的代码一段时间,我立刻想到你使用的是遗留的。我知道这已经被废弃了(请参阅https://developers.google.com/mobile-ads-sdk/android-legacy/),这意味着您不能使用这个程序向Play Store提交应用程序。它将被简单地拒绝。但我不确定这是否是原因。我没有收到您收到的错误消息。相反,我收到了:

代码语言:javascript
复制
No AdResponse found, <message: /log> 
Bad request.
onFailedToReceiveAd(Invalid Ad request.)

这意味着您从服务器上得到了一些信息。所以你的要求是正确的。因此,我做了一些研究,发现在最初几次不返回广告是很常见的(在这个论坛中有相当多的答案表明了这一点),这个问题似乎存在于遗留SDK中。所以这可能就是原因。除此之外,我什么都想不出来了。我有一些理论,但在我确定之前,我需要做一些研究。另外,在一个侧面,你需要:

代码语言:javascript
复制
ads:testDevices="your device id goes here" // one you get when you type adb devices
// this is to ensure that the services know you are simply testing and not using your own account to hit the service

最后,我建议您迁移到Google服务Ad反应时间。我以前只为练习和学习的目的而使用它,而且效果很好。希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29478769

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档