android - 似乎无法同时显示 ListView 和 AdView

标签 android listview admob adview

我的应用程序中有一个 Activity,它只显示一些搜索结果。此数据使用 ListView 显示。这很好用。我最近尝试在它下面添加一个 Adview,但它根本不显示。更重要的是,它会将我的 ListView 推到屏幕顶部,这样它只能占据屏幕顶部 20% 左右的空间 - 下面只有空白。

这是显示 XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:myapp="http://schemas.android.com/apk/res/uk.co.redfruit.android.whogotwhat"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"
    >
    <ListView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:id="@+id/scanResults"
        android:paddingLeft="5dp" 
        android:paddingRight="5dp" 
        />
    <com.admob.android.ads.AdView 
        android:id="@+id/ad"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        myapp:backgroundColor="#000000"
        myapp:primaryTextColor="#FFFFFF"
        myapp:secondaryTextColor="#CCCCCC" 
        />
</LinearLayout>

我在这里错过了什么?

最佳答案

对于初学者,请使用 android:orientation="vertical"在你的 LinearLayout 上,否则它将默认为 horizontal一。其次,尝试设置 LinearLayout的高度为 fill_parent并设置你的 ListView高度为 0px但带有 layout_weight1 .如果它仍然不正常,我猜 admob 的 AdView表现不佳并忽略了 wrap_content指令 -- 尝试将其高度固定为 dip 中的特定大小(无论如何,Admob 应该告诉您他们将在那里提供的尺寸是多少)。

关于android - 似乎无法同时显示 ListView 和 AdView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4378954/

相关文章:

android - Admob 低于背景

php - 为什么我的 mysql 查询总是返回空结果?

android - 如何编写 Android 应用程序来执行 sysfs 读/写。?

android - Android 中任何应用程序崩溃时如何获取通知

android - Android 移动框架 odoo v1 的 ListView 出现故障

android - 查看生成的ListView时间

android - 如何使图像按钮可见/不可见

android - 如何让广告显示在屏幕底部而不重叠

android - 双 GridView 同时和同步滚动

android - 如何在 ListView 中拥有高级列表项