Android Canvas GamePanel上的AdMob广告

时间:2013-05-21 19:56:17

标签: java android admob android-canvas

我想在画布表面视图上放置一个adob adbanner。 (扩展SurfaceView并实现SurfaceView.Callback的类)。 任何将视图放在顶部的解决方案?例如一个基本按钮。

1 个答案:

答案 0 :(得分: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 ...也可以实现相同的目标。