【问题标题】:Android - admob and SurfaceView issueAndroid - admob 和 SurfaceView 问题
【发布时间】:2012-07-27 16:10:01
【问题描述】:

我正在尝试开始使用 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 “窃取”了广告的空间。

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

你的,卢卡斯

【问题讨论】:

    标签: android admob surfaceview


    【解决方案1】:

    您是否尝试过使用 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);
    

    【讨论】:

    • 我不知道为什么,但它有效 :) 非常感谢,这个问题已经花费了我几个小时,如果没有你的帮助,我会花费更多,谢谢!
    猜你喜欢
    • 2011-09-19
    • 2013-04-01
    • 2011-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多