0

我正在尝试开始使用 admob,但它似乎比我想象的要难。我只是想编写一个小测试应用程序,在其中我会在表面视图上绘制一些东西并添加一个 admob 示例。

在我的主要活动中,我在 onCreate 方法中执行以下操作:

AndroidFastRenderView 是我对 SurfaceView 的实现。

requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;

        int frameBufferWidth = isLandscape ? 480 : 320;
        int frameBufferHeight = isLandscape ? 270 : 430;

        Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth,
                frameBufferHeight, Config.RGB_565);


        renderView = new AndroidFastRenderView(this, frameBuffer);
        graphics = new AndroidGraphics(getAssets(), frameBuffer);

        adView = new AdView(this, AdSize.BANNER, "XXX");
        adView.setVisibility(View.VISIBLE);


        FrameLayout layout = new FrameLayout(this);
        FrameLayout.LayoutParams gameParams = new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT,
                FrameLayout.LayoutParams.WRAP_CONTENT);

        FrameLayout.LayoutParams adsParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                FrameLayout.LayoutParams.WRAP_CONTENT);

        layout.addView(adView, 0, adsParams);

        layout.addView(renderView, 1, gameParams);
        setContentView(layout);


        AdRequest adRequest = new AdRequest();
        adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
        adView.loadAd(adRequest);

当我这样做时,整个屏幕都充满了 AndroidFastRenderView。但是,当我不添加 AndroidFastRenderView 时,会出现广告。所以我认为问题在于,也许 AndroidFastRenderView 绘制在我的广告上方(也许我对帧缓冲区的大小做错了)或者 AndroidFastRenderView “窃取”了广告的空间。

我希望你明白我的问题是什么,任何人都可以帮助我解决我的问题

你的,卢卡斯

4

1 回答 1

0

您是否尝试过使用 RelativeLayout 而不是 FrameLayout?

final int adId = 0x12345;
adView.setId(adId);
RelativeLayout layout = new RelativeLayout(this);

RelativeLayout.LayoutParams adParams =
    new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                                    RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
RelativeLayout.LayoutParams gameParams =
    new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                                    RelativeLayout.LayoutParams.WRAP_CONTENT);
gameParams.addRule(RelativeLayout.BELOW, adId);
layout.addView(adView, adParams);
layout.addView(renderView, gameParams);
setContentView(layout);
于 2012-07-27T22:21:20.733 回答