Currently I have a game in libgdx that show ads on top of the game layout. However, as you can notice, it hides part of the top of the screen, where the score is shown.
Question: How can I make the ads show ABOVE the game view/screen, so it doesnt overlap/hides anything from the game? I want the screens to be as shown in the next picture.
Current code:
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import de.golfgl.gdxgamesvcs.GpgsClient;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
public class AndroidLauncher extends AndroidApplication {
private RelativeLayout layout;
private RelativeLayout.LayoutParams params;
private AdView bannerAd;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
//
GpgsClient gpgsClient = new GpgsClient();
gpgsClient.initialize(this, false);
SpaceEscape game = new SpaceEscape(gpgsClient);
//
//initialize(game, config);
View gameView = initializeForView(game,config);
////////// Define the layout
layout = new RelativeLayout(this);
layout.addView(gameView, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
params = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
bannerAd = new AdView(this);
bannerAd.setAdUnitId("REDACTED");
bannerAd.setAdSize(AdSize.BANNER);
layout.addView(bannerAd, params);
setContentView(layout);
AdRequest ad = new AdRequest.Builder().build();
bannerAd.loadAd(ad);
}
}