我(第一次)在我的活动类中使用AdMob com.google.ads.AdView标记。问题是,当我打开活动时,我的文本视图和活动上的图像显示1,2秒后,然后AdView Display Add`s和我的活动TextView和ImageView变为空白。我尝试以两种方式包含添加,但两者都显示添加和消除活动。
使用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使用活动:
我从此方法的activity.xml中删除了<com.google.ads.AdView />
activity.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);
*
答案 0 :(得分:0)
在我看来,您可能会尝试加载广告两次。我建议从java中删除所有AdView引用。您无需致电:
myAdView = (AdView)findViewById(R.id.adView);
myAdView.loadAd(new AdRequest());
因为您在XML中设置了ads:loadAdOnCreate="true"
。
另一个建议:
尝试从XML和Java中删除AdView内容,以查看Activity是否以这种方式正确显示。
答案 1 :(得分: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"
>
我发现android:padding="5dp"
标记不应在AdView的主要布局中使用,否则会出现以下错误。 Not enough space to show ad! Wants: 480, 75, Has: 320, 52
Leo Landau感谢您的帮助:)。