2

アクティビティ クラスで (初めて) AdMob com.google.ads.AdView タグを使用しています。問題は、アクティビティを開くと、アクティビティのテキスト ビューと画像が 1.2 秒間表示され、その後 AdView Display Add`s とアクティビティ TextView と ImageView が空白になることです。私は 2 つの方法で追加を含めようとしましたが、どちらも追加と消失アクティビティを示しています。

XML を使用した AdView :

                          **activity.xml**


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/result_Activity_Layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/love_result_background" >

    <TableRow
        android:id="@+id/mainLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

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

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dp" >

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:stretchColumns="*"
            tools:context=".MyActivity" >

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/TextViewFirstName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:paddingTop="10dp"
                    android:shadowColor="@color/name_Shadow"
                    android:shadowDx="2"
                    android:shadowDy="2"
                    android:shadowRadius="4"
                    android:text="@string/my_name"
                    android:textColor="@color/name_Text"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/TextViewFirstNameScore"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:paddingTop="10dp"
                    android:shadowColor="@color/score_Shadow"
                    android:text="@string/result"
                    android:textColor="@color/score_Text"
                    android:textSize="26sp"
                    android:textStyle="bold" />
            </TableRow>
        </TableLayout>
    </ScrollView>

</LinearLayout>
                                 **activity.java**

// AdMobWidget in onCreate()
        myAdView = (AdView)findViewById(R.id.adView);
        myAdView.loadAd(new AdRequest());

AdView Using Activity :<com.google.ads.AdView />このメソッドで activity.xml から 削除します

アクティビティ.java *

// following code use in onCreate() method
    myAdView = new AdView(this, AdSize.BANNER, "a1s310e4e43247c");

    LinearLayout rootView = (LinearLayout)this.findViewById(R.id.result_Activity_Layout);
    LinearLayout.LayoutParams layoutParams = new LayoutParams(480, 75);
    rootView.addView(myAdView, 0, layoutParams);        

    AdRequest re = new AdRequest();
    re.setGender(AdRequest.Gender.UNKNOWN);
    myAdView.loadAd(re);

*

4

2 に答える 2

0

線形レイアウトに次の行を含めるだけandroid:orientation="vertical"で、追加が機能し始めます。yappiiii ....私は何時間もかけてその解決策を得ました

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
     >

AdView のメイン レイアウトでandroid:padding="5dp"タグを使用しないでください。そうしないと、次のエラーが発生しました。 Not enough space to show ad! Wants: 480, 75, Has: 320, 52

レオ・ランダウ、助けてくれてありがとう:)

于 2013-02-07T19:07:05.223 に答える
0

広告を 2 回読み込もうとしているようです。Java からすべての AdView 参照を削除することをお勧めします。電話する必要はありません:

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

ads:loadAdOnCreate="true"XMLで設定しているためです。

別の提案:

XML と Java の両方から AdView のものを削除して、Activity が適切に表示されるかどうかを確認してください。

于 2013-02-06T18:52:24.780 に答える