2014-06-27 4 views
0

J'ai développé un jeu en xcode en utilisant cocos2d-x & converti en android.Puis j'ai ajouté google play services annonce, mais il est affiché dans leftsidecorner. Je veux l'afficher au milieu. S'il vous plaît, aidez-moi à trouver la solution.google play services annonce affiche dans le coin dans android

private Point getDisplaySize(Display d) 
{ 
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) 
    { 
     return getDisplaySizeGE11(d); 
    } 
    return getDisplaySizeLT11(d); 
} 
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) 
private Point getDisplaySizeGE11(Display d) 
{ 
    Point p = new Point(0, 1); 
    d.getSize(p); 
    return p; 
} 
private Point getDisplaySizeLT11(Display d) 
{ 
    try 
    { 
    Method getWidth = Display.class.getMethod("getWidth", new Class[] {}); 
    Method getHeight = Display.class.getMethod("getHeight", new Class[] {}); 
    return new Point(((Integer) getWidth.invoke(d,(Object[]) null)).intValue(),        
    ((Integer) getHeight.invoke(d, (Object[]) null)).intValue()); 
    } 
    catch (NoSuchMethodException e2) // None of these exceptions should ever occur. 
    { 
     return new Point(-1, -1); 
    } 
    catch (IllegalArgumentException e2) 
    { 
     return new Point(-2, -2); 
    } 
    catch (IllegalAccessException e2) 
    { 
     return new Point(-3, -3); 
    } 
    catch (InvocationTargetException e2) 
    { 
     return new Point(-4, -4); 
    } 
    } 
     @Override 

protected void onCreate(Bundle savedInstanceState){ 
super.onCreate(savedInstanceState); 
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 

    int width = getDisplaySize(getWindowManager().getDefaultDisplay()).y; 
    FrameLayout.LayoutParams adParams = new FrameLayout.LayoutParams(
    LayoutParams.WRAP_CONTENT, 
    LayoutParams.WRAP_CONTENT); 
    adParams.gravity = Gravity.BOTTOM; 
    adView = new AdView(this); 
    adView.setAdSize(AdSize.BANNER); 
    adView.setAdUnitId(AD_UNIT_ID); 


    AdRequest adRequest = new AdRequest.Builder() 
    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) 
    .addTestDevice("HASH_DEVICE_ID") 
    .build(); 
    adView.loadAd(adRequest); 
    adView.setBackgroundColor(Color.BLACK); 
    adView.setBackgroundColor(0); 
    addContentView(adView,adParams); 
    _appActiviy = this; 
    } 
+0

Affichez votre mise en page. –

+0

Je n'utilise aucune disposition. J'utilise uniquement le code d'annonce google play services dans le fichier .java. – arunkumar

+0

Si vous affichez quelque chose, vous utilisez une mise en page. –

Répondre

0

Dans votre code ci-dessus apporter les modifications suivantes.

Trouver le code ci-dessous

adParams.gravity = Gravity.BOTTOM; 

Modifier comme suit

adParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; 

Ensuite, l'ajout affiche au milieu de votre fond d'application.

+0

Merci pour votre commentaire. – arunkumar

Questions connexes