0

我在列表视图底部显示广告时遇到问题,在我的主要活动中,广告有效,唯一的区别是我使用 viewpager 而不是列表视图。

这是布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.google.ads.AdView
        xmlns:app="http://schemas.android.com/apk/lib/com.google.ads"
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        ads:loadAdOnCreate="true"
        android:background="#313131"
        app:adSize="SMART_BANNER"
        app:adUnitId="MY_ID" />

    <ListView
        android:id="@id/android:list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/adView" />

</RelativeLayout>

列表视图显示在广告的顶部,当然不能点击,但同样的布局适用于 viewpager。

4

3 回答 3

0

最终布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.google.ads.AdView
        xmlns:app="http://schemas.android.com/apk/lib/com.google.ads"
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        ads:loadAdOnCreate="true"
        android:background="#313131"
        app:adSize="SMART_BANNER"
        app:adUnitId="MY_ID" />

    <LinearLayout
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/adView" />

</RelativeLayout>

然后替换:

getSupportFragmentManager().beginTransaction().add(android.R.id.content, list).commit();

和:

getSupportFragmentManager().beginTransaction().add(R.id.listview, list).commit();
于 2013-04-09T08:00:33.833 回答
0

另一种方式。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ListView
    android:id="@id/android:list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   />

<com.google.ads.AdView
    xmlns:app="http://schemas.android.com/apk/lib/com.google.ads"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ads:loadAdOnCreate="true"
    android:background="#313131"
    app:adSize="SMART_BANNER"
    app:adUnitId="MY_ID" />

</LinearLayout >

加载 Ad - 时,获取他的身高。然后ListView bottomMargin = adHeightAd topMargin = (-1)*adHeight。试试看。

于 2013-04-09T06:46:58.740 回答
0

<ListView
    android:id="@id/android:list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
   />

<com.google.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#313131"
    ads:loadAdOnCreate="true"
    ads="SMART_BANNER"
    ads="MY_ID" />

注意这是一个布局问题。它与 Admob 无关。如果您使用的是 LinearLayout,那么只需为要扩展的项目设置 layout_height="wrap+content" 和 layout_gravity="1" 以消耗未使用的空间。在这种情况下,您的 ListView。

您的问题实际上是 layout_height="match_parent"

注意我还删除了广告命名空间的不必要重命名。

于 2013-04-09T10:49:14.333 回答