我的应用程序中有一个 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_weight
的 1
.如果它仍然不正常,我猜 admob 的 AdView
表现不佳并忽略了 wrap_content
指令 -- 尝试将其高度固定为 dip
中的特定大小(无论如何,Admob 应该告诉您他们将在那里提供的尺寸是多少)。
关于android - 似乎无法同时显示 ListView 和 AdView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4378954/