1

我正在尝试使用 listView 将 adView 添加到我的布局中,但由于某种原因,adview 没有显示。它适用于其他活动,但不会显示在带有 listView 的活动上。这是我正在使用的代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <com.google.ads.AdView android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adUnitId="ID"
        ads:adSize="BANNER"
        ads:loadAdOnCreate="true"/>

  <ListView android:id="@+id/listView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>

</LinearLayout>

有任何想法吗?

4

2 回答 2

-1

我一直觉得布局有点棘手。对于 listView,您是否尝试过设置android:layout_width匹配父项?我经常发现我不得不在各种 XML 对象中摆弄这些参数。如果可能,还可以尝试(暂时)取出 ListView 并查看广告是否出现。

于 2011-10-28T21:51:24.400 回答
-1

问题是列表视图设置为填充父级。所以它占用了整个屏幕,并关闭了 adview。至少有两种解决方案:最简单的,将 android:layoutWeight ="1" 添加到每个节点。这告诉他们共享空间

 <com.google.ads.AdView android:id="@+id/adView"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adUnitId="ID"
        ads:adSize="BANNER"
        ads:loadAdOnCreate="true"/>

  <ListView android:id="@+id/listView1"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>

另一种方法是使用 FrameLayout 或 RelativeLayout 而不是线性布局,以便 View 可以彼此重叠或相对于彼此定位。我建议使用RelativeLayout,这样广告就不会覆盖您的ListView 的一部分。然后使用 android:layout_below="@id/adView" 将您的 ListView 定位在 adView 下方。

于 2011-10-28T21:59:43.203 回答