ゲームに admob を追加しようとしています。キャンバスを描画するために surfaceview を使用しています。これがメイン レイアウトです。
<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_alignParentBottom="true"
android:layout_alignParentLeft="true"
ads:adSize="BANNER"
ads:adUnitId="a151e48ea219c98"
android:visibility="visible" />
</RelativeLayout>
そして主な活動はこちら
MykSurface ourSurfaceView;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ourSurfaceView = (MySurface) findViewById(R.id.surface);
}
これは、描画キャンバスをサーフェス上で実行するクラスです
public class MySurface extends SurfaceView implements Runnable {
.....
@Override
public void run() {
// TODO Auto-generated method stub
while (isRunning) {
canvas.drawBitmap(bg, 0, 0, null);
}
.....
}
問題は、ourSurfaceView をレイアウト上の surfaceview に「接続」して描画に使用できないことです。