2014-11-22 39 views
1

我想是這樣的另外兩個問題:
Android AdMob Vertical ads
How to show admob ads vertical in landscape mode? (Android)如何在ladscape模式(使用libgdx)顯示垂直admob廣告?

而且我從這個開始: https://github.com/TheInvader360/tutorial-libgdx-google-ads

我那麼努力把左側豎旗幟風景模式,但我只有在篩選中心得到垂直admob,我不能移動到左邊。

另外,我正在做兩個不同的「層」:旗幟重疊的應用程序視圖。我想要這個,因爲我需要全屏顯示應用程序視圖。

另一點:我需要暫停和恢復應用程序來顯示橫幅,看起來像「layout.bringChildToFront」之前調用廣告加載,所以不工作。

(我沒有什麼特別的,在AndroidManifest.xml中,我試圖通過代碼來做到這一點)

<activity 
     android:name="com.google.android.gms.ads.AdActivity" 
     android:screenOrientation="landscape" 
     android:orientation="vertical" 
     android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" 
    /> 

這裏是我的代碼:(我使用LIBGDX)

public class AndroidLauncher extends AndroidApplication { 

     private static final String AD_UNIT_ID_BANNER = "ca-app-pub-7938591782705263/4150532439"; 

     protected AdView adView; 
     protected View gameView; 


     @Override 
     public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration(); 
     cfg.useAccelerometer = false; 
     cfg.useCompass = false; 

     // Do the stuff that initialize() would do for you 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); 

     FrameLayout layout = new FrameLayout(this);//base container layout 
     FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); 
     layout.setLayoutParams(params); 

     AdView admobView = createAdView();//ads the banner and the app view to the base layout 
     layout.addView(admobView); 
     View gameView = createGameView(cfg); 
     layout.addView(gameView); 

     setContentView(layout); 
     startAdvertising(admobView); 
     layout.bringChildToFront(admobView);//this is currently not working, I need to pause and resume app to show the banner 

     } 

     private AdView createAdView() { 
     adView = new AdView(this); 
     adView.setAdSize(AdSize.SMART_BANNER); 
     adView.setAdUnitId(AD_UNIT_ID_BANNER); 
     adView.setId(12345); 
     LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.LEFT|LinearLayout.FOCUS_LEFT|Gravity.TOP|LinearLayout.FOCUS_UP); 

     //last hard try to get vertical banner at left side :/ 
     adView.setRotation(270); 
     adView.setPadding(0, 0, 0, 0); 
     adView.setTop(0); 
     adView.setLeft(0); 
     adView.setRight(0); 
     adView.setX(0); 
     adView.setY(0); 
     adView.refreshDrawableState(); 
     adView.setLayoutParams(params); 
     return adView; 
     } 

     private View createGameView(AndroidApplicationConfiguration cfg) { 
     gameView = initializeForView(new Main(), cfg); 
     FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 

     gameView.setLayoutParams(params); 
     return gameView; 
     } 

     private void startAdvertising(AdView adView) { 
     AdRequest adRequest = new AdRequest.Builder().build(); 
     adView.loadAd(adRequest); 
     } 


     @Override 
     public void onResume() { 
     super.onResume(); 
     if (adView != null) adView.resume(); 
     } 

     @Override 
     public void onPause() { 
     if (adView != null) adView.pause(); 
     super.onPause(); 
     } 

     @Override 
     public void onDestroy() { 
     if (adView != null) adView.destroy(); 
     super.onDestroy(); 
     } 
(...) 

非常感謝,祝你有美好的一天! )

回答

0

通過具有FrameLayout含有GameView並且含有AdView與相對佈局PARAMS(渦卷內容和左對齊父的相對佈局)和變化的旋轉樞軸然後rotateview工作正常解決。

但廣告仍然不可見,我試過這個:Admob ads appear only after first refresh並沒有工作。我必須按回家並恢復應用程序才能看到廣告...

+0

請問您能詳細解釋一下這個答案嗎? – 2017-09-21 18:52:02