0

I have the following MainActivity xml file

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"

    xmlns:ads="http://schemas.android.com/apk/res-auto"

    android:id="@+id/mainLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.retrochicken.slide.MainActivity">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="bottom|start"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id">
    </com.google.android.gms.ads.AdView>

</FrameLayout>

And then in the MainActivity java class OnCreate method

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.activity_main);

        FrameLayout mainLayout = (FrameLayout) findViewById(R.id.mainLayout);
        mainLayout.addView(new GamePanel(this));

        MobileAds.initialize(getApplicationContext(), "ca-app-pub-3940256099942544~3347511713");

        AdView mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);

        mAdView.bringToFront();
    }

I am trying to have my GamePanel class, which is a SurfaceView, draw a canvas the the entire screen, but have a ad banner on the bottom of the screen display on top of it. Currently I see nothing happening with the ads, it could be some other issue but I'm guessing that it is shown behind what's being drawn by the GamePanel.

EDIT
I have confirmed that it is an issue of the GamePanel drawing on top of the AdView, I believe it may be how I am handling the draw methods. In GamePanel I have a method draw(Canvas canvas) that draws all the Game Objects onto the canvas, I then post the canvas to the screen using

try {
                canvas = this.surfaceHolder.lockCanvas();
                synchronized (surfaceHolder) {
                    this.gamePanel.update(timeMillis);
                    this.gamePanel.draw(canvas);
                }
            } catch(Exception e) {

            } finally {
                if(canvas != null) {
                    try {
                        surfaceHolder.unlockCanvasAndPost(canvas);
                    } catch(Exception e) {e.printStackTrace();}
                }
            }

which is contained in a while loop that repeats (in another thread) that controls the frames of the game.

2 Answers2

0

Based on the information here, perhaps you can try

mAdView.setWillNotDraw(false);
jeyoor
  • 938
  • 1
  • 11
  • 20
0

It is the functionality of FrameLayout to show a single View at a time and block the other more detail https://developer.android.com/reference/android/widget/FrameLayout.html

Syed
  • 320
  • 3
  • 11