3

I am currently able to get the admob ads on ui view (in separate test project ), but i want to display this ad in GLSurfaceView . I tried to load the ad in onCreate( ) method of activity and in present method of my screen (where all rendering is done) i called

MyGameActivity.mAdView.bringToFront(); //thought it will bring the ad in front of all the game objects.

now on running the project i can see the message in logcat window Recieved ad url "big url" but i cant see the ad on screen. In my game there is only one activity and many game screens. please help me figure out how to display ads on my game screen.

appdroid
  • 573
  • 7
  • 18
  • What does your layout look like? – Kenny C Oct 02 '12 at 11:46
  • i set the layout in java code not in xml file, below is the code AdView mAdView = new AdView(this, AdSize.BANNER, "id"); FrameLayout layout=new FrameLayout(this);//(FrameLayout) this.findViewById(R.id.adViewLayout); FrameLayout.LayoutParams adsParams =new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, android.view.Gravity.BOTTOM|android.view.Gravity.CENTER_HORIZONTAL); layout.addView(GLGame.mAdView, adsParams ); mAdView.loadAd(new AdRequest()); – appdroid Oct 02 '12 at 11:49
  • 1
    Do you add your GLSurfaceView to the same FrameLayout? If so can you post that code. If your not then that is your problem. – Kenny C Oct 02 '12 at 12:32
  • i added the framelayout to the contentView now i got the ad displayed on the screen. but i want it to be invisible when user is on gameScreen(while playing) i tried on load of the gameScreen to set visibility of framelayout to invisible but it shows error that only the thread which started the view can change this property ... have any idea how to fix this??? – appdroid Oct 02 '12 at 12:48

1 Answers1

1

You should modify your layout to be something like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layoutMain"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >       
    <RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/layout1"
        android:tag="trueLayout"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        >       
    </RelativeLayout>
</LinearLayout>

This is my code, which is self explanatory.:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);        

    setContentView(R.layout.main);

    LinearLayout layoutMain = (LinearLayout) findViewById(R.id.layoutMain);

    // Create the adView
    // Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
    adView = new AdView(this, AdSize.BANNER, "YourPersonalID#"); 

    layoutMain.addView(adView);

    // Initiate a generic request to load it with an ad
    AdRequest request = new AdRequest();
    request.setTesting(true);

    adView.loadAd(request);     

    RelativeLayout layout1 = (RelativeLayout) findViewById(R.id.layout1);
    layout1.setOnTouchListener(this);

    mTestHarness = new GLSurfaceView(this);
    mTestHarness.setEGLConfigChooser(false);
    mTestHarness.setRenderer(this);
        mTestHarness.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);    

    layout1.addView(mTestHarness);
}

After you get this right you will get the equivalent to the BannerEssentials tutorial app from the google play tutorials, but using GLSurfaceView instead.

Pixelapp
  • 193
  • 1
  • 10