0

我陷入了CCGLSurfaceView与其他android原生视图一起工作的问题ImageView,例如。我开始使用 Cocos2D 开发游戏,我打算稍后通过 admob 在其中添加广告。因此,我想在顶部运行CCGLSurfaceView(我的游戏的OpenGL视图),广告应显示在其下方。

我已经尝试了几件事,例如手动(不是通过 XML)将两个视图添加到相对布局中,但不断获取null pointers并且我的应用程序强制关闭。

我还尝试了本教程,他们解释了如何集成admobOpenGl SurfaceView. 但是还是不行,可能是因为我用的是Cocos2d?

我不知道,有人可以帮我解决这个(也许是 cocos2d 特定的)问题吗?

4

1 回答 1

1

我们需要您的代码(总体而言,将链接指向您所基于的内容并不是很有帮助)

我的方法是在布局中定义所有这些

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:gravity="center"
        android:orientation="vertical" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <LinearLayout 
            android:gravity="center_horizontal"
            android:orientation="horizontal"
            android:layout_alignParentTop="true"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

        </LinearLayout>

        <android.pixelrain.opengl.GLSurfaceViewChipmunk android:id="@+id/composed"
            android:gravity="center"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
        />

        <LinearLayout
            android:id="@+id/linearLayoutAd"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:layout_alignParentBottom="true"
            android:orientation="vertical"
            android:gravity="center_horizontal"
        />

</RelativeLayout>

注意 GLSurfaceViewChipmunk 是你用 cocos2d 替换的。

然后在应用程序中

 private void InitAdView()
    {
        LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayoutAd);

        // Create the adView
        adView = new AdView(this, AdSize.BANNER, AppSettings.AdmobAppId);

        ...set your add listener

        // Add the adView to the layout
        layout.addView(adView);
于 2011-06-24T10:14:35.253 回答