I'm using an AdMob view which has no width/height until it's ready to be displayed and then it expands. is there a way to get notified when that happens? I need to resize my layout when that happens.
Asked
Active
Viewed 843 times
4 Answers
2
You could override the onLayout
method of your view:
View view = new View(this) {
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
// Do some stuff
}
};

sdabet
- 18,360
- 11
- 89
- 158
1
Try using this
AdView.setAdListener(new AdListener() {
public void onRecieveAd(){
//resize your view
}
});
If you want to know when your adview has recieve an ad, then you can use an onFailedToRecieveAd
listener.
AdView.setAdListener(new AdListener() {
public void onFailedToRecieveAd(){
//do something else
}
});
1
If you use relative layouts that put the adMob in an effective location, then it works best. You can actually place the adMob image such that it is a part of the layout. When the image comes in, the layout gets shuffled around appropriately.
Alternatively, you can look into adListeners
public interface AdListener {
public void onReceiveAd(Ad ad);
public void onFailedToReceiveAd(Ad ad, AdRequest.ErrorCode error);
public void onPresentScreen(Ad ad);
public void onDismissScreen(Ad ad);
public void onLeaveApplication(Ad ad);
}
Essentially, you can set the addListener and do something when an ad was received. But I recommend using a relative layout with the adMob included in the XML code, such that the layout automatically adjusts when the image appears/disappears.

PearsonArtPhoto
- 38,970
- 17
- 111
- 142
0
you can use something like
public void onCreate(Bundle savedInstanceState)
{
...
make admob...
...
AdSize adSize = AdSize.createAdSize(AdSize.SMART_BANNER, this);
int h = adSize.getHeightInPixels(getBaseContext());
myListView.setPadding(0, 0, 0, h);
}

MrSwan
- 31
- 2