2013-07-16 94 views
0

我是Java和Android的初学者,我需要将admob广告放置在SurfaceView上方,它不起作用。有人可以帮我做到这一点吗?这是布局的代码:将admob广告放置在surfaceview上

 <?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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"> 

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

    android:layout_alignParentTop="true" 
    ads:adSize="BANNER" 
    ads:adUnitId="a151e3f18d34b57" 
    ads:loadAdOnCreate="true" 
    ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" /> 

    <SurfaceView 
    android:id="@+id/preview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    /> 


    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 

     android:src="@drawable/gunmask" /> 


</RelativeLayout> 
+0

什么是 '不工作' 是什么意思?你得到了什么? –

+0

广告正在发挥作用,但它是隐形的?我注意到它从堆栈跟踪 – user2558256

回答

2

你必须把对的RelativeLayout的android:orientation属性和android:layout_below属性在您的表面。

下面将放置您设置的@id之后的视图。

我删除android:layout_alignParentTop="true"

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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:orientation="vertical"> 

    <com.google.ads.AdView 
    android:id="@+id/adView" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    ads:adSize="BANNER" 
    ads:adUnitId="a151e3f18d34b57" 
    ads:loadAdOnCreate="true" 
    ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" /> 

    <SurfaceView 
    android:layout_below="@id/adView" 
    android:id="@+id/preview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"/> 


    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:src="@drawable/gunmask" /> 
</RelativeLayout> 
+0

它的工作!谢谢 – user2558256