0

我是 Java 和 android 的初学者,我需要将 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>
4

1 回答 1

2

您必须在您的表面放置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>
于 2013-07-16T20:52:52.080 回答