Android 使用列表视图添加到布局时,Adview不可见

Android 使用列表视图添加到布局时,Adview不可见,android,listview,adview,Android,Listview,Adview,我正在尝试使用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:orientati

我正在尝试使用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>


有什么想法吗?

我总是觉得布局有点棘手。对于listView,您是否尝试过将android:layout\u width设置为与父级匹配?我经常发现我不得不在各种XML对象中处理这些参数。如果可能的话,还可以尝试(暂时)取出列表视图,看看广告是否出现。

问题是列表视图设置为填充父视图。因此,它占据了整个屏幕,并将adview关闭。 至少有两种解决方案: 最简单的, 将android:layoutwweight=“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而不是线性布局,以便视图可以彼此重叠或相对放置。我建议使用相对论,这样广告就不会覆盖部分列表视图。然后使用android:layout_below=“@id/adView”将您的列表视图定位到adView下方