0

プログラムに admob を追加したいのですが、常に 1 つではなく 2 つの広告が表示されます。アクティビティの一番上に広告を表示したい。これらの 2 つの広告が上にくっついています。一方を削除するにはどうすればよいですか?

ここにxmlがあります:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:gravity="top"
tools:context=".MainActivity" >

<ImageButton
    android:id="@+id/btnSwitch"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_marginTop="25dp"
    android:background="@null"
    android:contentDescription="@null"
    android:src="@drawable/btn_switch_on" />


<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/textView2"
    android:layout_centerHorizontal="true"
    android:text="@string/Develop"
    android:textColor="#C0C0C0"
    android:textSize="15sp" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:padding="5dp"
    android:text="@string/soheilen"
    android:textColor="#C0C0C0"
    android:textSize="18sp" />

<ImageButton
    android:id="@+id/imageButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:background="@null"
    android:contentDescription="@null"
    android:minHeight="64dp"
    android:minWidth="64dp"
    android:src="@drawable/more" />

<ToggleButton
    android:id="@+id/toggleButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:text="@string/mute"
    android:textOff="@string/mute"
    android:textOn="@string/mute" />







    <LinearLayout 

        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:id="@+id/mainline" 
        android:gravity="top"
        >

<com.google.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    ads:adSize="BANNER"
    ads:adUnitId="aXXXXXXXXXXb"
    ads:loadAdOnCreate="true"
    android:gravity="top" >
   </com.google.ads.AdView>     

    </LinearLayout>



</RelativeLayout>

ここにメインのJavaの私のコードがあります:

AdView adView = (AdView)this.findViewById(R.id.adView);
   AdRequest adRequest = new AdRequest();

    adView = new AdView(this, AdSize.BANNER,"xxxxxxxxxxxx");


    LinearLayout layout = (LinearLayout) findViewById(R.id.mainline);

    layout.addView(adView);

    adView.loadAd(adRequest);

相対レイアウトなどの他の設定を試しましたが、正しく機能しません!

4

2 に答える 2

1

を使用している場合ads:loadAdOnCreate="true"、Java ファイルにコードを追加する必要はありません。広告リクエストが 2 回行われ、リクエストが予想外に増える可能性があると思います。Java ファイルの広告リクエスト コードを削除し、XML コードのみを残します。リンク:-リンク

于 2013-05-29T18:14:02.180 に答える
1

AdViewコードとxmlに追加したことを除いて、コードは正常に機能します。いずれかを削除して実装できます。

AdView adView = (AdView)this.findViewById(R.id.adView);
   AdRequest adRequest = new AdRequest();           
    adView.loadAd(adRequest);

ハッピーコーディング:)

于 2013-05-28T22:13:06.347 に答える