user642252
user642252

Reputation: 522

Can't get AdView over my GLSurfaceView

I am not much experienced on Android layouts. What am I doing wrong?

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

    adView = new AdView(this, AdSize.BANNER, MY_CODE);
    adView.loadAd(new AdRequest());
    adView.setVisibility(AdView.VISIBLE);
}

and my onStart:

public void onStart() {
    super.onStart();
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    this.addContentView(adView, params); // it is ok?
}

Upvotes: 2

Views: 1368

Answers (1)

user642252
user642252

Reputation: 522

The thing is, unlike the iOS, you can't set a view as a GLSurfaceView's subview, the solution was:

adView = new AdView(this, AdSize.BANNER, CODE);
rl = new RelativeLayout(this);

LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
this.addContentView(rl, params);
adView.loadAd(new AdRequest());
rl.addView(adView);
rl.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
rl.bringToFront();

Upvotes: 3

Related Questions