読者です 読者をやめる 読者になる 読者になる

フニゲの開発日記

Electronとか...

nendのバナーをセンタリングして表示

Android


メモ

...

public class giin extends Cocos2dxActivity{
    private static NendAdView nendAdView = null;
    private static giin me = null;
    private static RelativeLayout relativeLayout = null;

    protected void onCreate(Bundle savedInstanceState){
	super.onCreate(savedInstanceState);
        me = this;
    }
	
    public static void showAd() {
        me.runOnUiThread(new Runnable() {
            public void run() {
                if (nendAdView == null) {
                    nendAdView = new NendAdView(me, [spotID], "[apiKey]");

                    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(320, 50);

                    lp.setMargins(0, 5, 0, 5); // ちょっと上下にスキマを空けたい
                    lp.addRule(RelativeLayout.CENTER_HORIZONTAL); // センタリング 
                    //lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); // 画面下の場合

                    relativeLayout = new RelativeLayout(me);
                    relativeLayout.addView(nendAdView, lp);

                    me.addContentView(relativeLayout, new RelativeLayout.LayoutParams(
                            RelativeLayout.LayoutParams.FILL_PARENT,
                            RelativeLayout.LayoutParams.FILL_PARENT));
                    
                    nendAdView.loadAd();
                }
                nendAdView.setVisibility(LinearLayout.VISIBLE);
            }
        });
    }

    public static void hideAd() {
        me.runOnUiThread(new Runnable() {
            public void run() {
                nendAdView.setVisibility(LinearLayout.INVISIBLE);
            }
        });
    }

    ...
広告を非表示にする