paused -> Show ad as banner.
playerlost -> show as fullscreen.
playing -> hide the ad.
MainActivity:
public class MainActivity extends Activity{
private tGame game;
//(...)
layout.addView(game);
layout.addView(admob, adParams);
setContentView(layout);
//(...)
}
另一种观点(tGame):
public class tGame extends View implements Runnable{
//(...)
int gameState = 0; // <- PLAYING, PAUSED, PLAYERLOST, etc.
//(...)
}
如何从其他视图(游戏)调整广告(admob)的大小?
答案 0 :(得分:0)
您可以使用公开标记来显示/隐藏广告并为全屏广告启动插页式广告:
if(paused)
adview.setVisibility(View.VISIBLE);
else if(playerlost)
interstitialAd.show();
else if(playing)
adview.setVisibility(View.INVISIBLE);
<强>更新强>
要修改其他类的广告,您可以使用外观:
定义一个接口,例如MyAdListener.java:
public interface MyAdListener{
public void showAd();
public void hideAd();
public void lauchFullScreenAd();
}
在游戏的主要活动中,实现界面:
public class MainActivity extends Activity implements MyAdListener{
private tGame game;
//(...)
layout.addView(game);
layout.addView(admob, adParams);
setContentView(layout);
//(...)
@Override
public void showAd(){
runOnUiThread(new Runnable() {
@Override
public void run(){
adview.setVisibility(View.VISIBLE);
}
);
}
@Override
public void hideAd(){
runOnUiThread(new Runnable() {
@Override
public void run(){
adview.setVisibility(View.INVISIBLE);
}
);
}
@Override
public void launchFullScreenAd(){
runOnUiThread(new Runnable() {
@Override
public void run(){
if (interstitial != null) interstitial.show();
}
);
}
}
然后最后在你的游戏课程中:
public class tGame extends View implements Runnable{
MyAdListener myAdListener;
public tGame(Context context){
myAdListener = (MyAdListener)context;
}
//(...)
int gameState = 0; // <- PLAYING, PAUSED, PLAYERLOST, etc.
//(...)
if(paused)
myAdListener.showAd();
else if(playerlost)
myAdListener.launchFullScreenAd();
else if(playing)
myAdListener.hideAd();
}