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" />

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

</RelativeLayout>

リストビューは広告の上部に表示され、もちろんクリックすることはできませんが、同じレイアウトがビューページャーで機能します。

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

<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" />

注意これはレイアウトに関する質問です。アドモブとは関係ありません。LinearLayout を使用している場合は、未使用のスペースを消費するために展開したい項目に対して、layout_height="wrap+content" と layout_gravity="1" を設定するだけです。この場合、あなたの ListView.

あなたの問題は本当に layout_height="match_parent" でした

NB また、ads 名前空間の不要な名前変更も削除しました。

于 2013-04-09T10:49:14.333 に答える
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 = adHeight_ Ad topMargin = (-1)*adHeightそれを試してみてください。

于 2013-04-09T06:46:58.740 に答える