2013-05-21 61 views

回答

1

實際上,您不需要在SurfaceView中添加它,您可以在添加SurfaceView後將其添加到SurfaceView的父ViewGroup中。

僞例:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

     <SurfaceView 
      android:id="@+id/surface" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_centerInParent="true" /> 

     <com.google.ads.AdView 
      xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
      android:id="@+id/ad" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      ads:adSize="BANNER" 
      ads:adUnitId="xxxxxxxxxxxxxxxxxx" 
      android:visibility="visible" /> 

</RelativeLayout> 

同樣也可以使用代碼而不是XML來實現......