我必须添加adView.loadAd(new AdRequest());显示Admob广告?

时间:2013-06-24 22:45:49

标签: android

以下来自示例应用的代码,运行良好,即使我删除AdView adView =(AdView)this.findViewById(R.id.adViewabout)和loadAd(新AdRequest(),我仍然可以显示Admob )。

为什么呢?谢谢!

public class AboutActivity  extends Activity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.about);     

        TextView mLink = (TextView) findViewById(R.id.tvMyLink);
        mLink.setMovementMethod(LinkMovementMethod.getInstance());

        // Look up the AdView as a resource and load a request.
        AdView adView = (AdView)this.findViewById(R.id.adViewabout);
        adView.loadAd(new AdRequest());

    }
}


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"   
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingTop="3dip"
    android:background="@drawable/border_ui"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/appversion"
        android:paddingLeft="7dip"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="7dip"
        android:text="V1.04" />

   <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/myabout"
        android:layout_marginTop="8dip"
        android:paddingLeft="7dip"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/tvMyLink"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="25dip"
        android:paddingLeft="7dip"
        android:text="@string/mylink" />

    <com.google.ads.AdView
        android:id="@+id/adViewabout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="a151bc26cd3bc22"
        ads:loadAdOnCreate="true" />

    <TextView
        android:id="@+id/tvOnlyTake"
        android:layout_width="wrap_content"
        android:layout_height="0dip"   
        android:layout_weight="1"     
        android:text="" />

     <Button
        android:id="@+id/btnClose"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        style="@style/myTextAppearance"
        android:text="@string/myreturn" />


</LinearLayout>

2 个答案:

答案 0 :(得分:2)

这是因为您已经在XML中创建了adRequest

如果您想在特定时间加载广告,或在活动中重新加载广告,您仍然可以使用loadAd(新AdRequest())

答案 1 :(得分:0)

我认为可能是因为你的布局xml说ads:loadAdOnCreate="true"