LoginSignup
4
5

More than 5 years have passed since last update.

cocos2d-xで作成したAndroidプロジェクトでlinearLayoutを使ってレイアウトを重ねる方法

Posted at

はじめに

cocos2d-xで開発したAndroidプロジェクトに広告等を入れる事があると思います。
cocos2d-xではxmlファイルを使ってレイアウトが出来ないので、直接レイアウトを記述する必要があります。
ここではcocos2d-xで作成したAndroidプロジェクトにレイアウトする方法をご紹介します。

実装方法

Activity
LinearLayout linearLayout=new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
//setだと落ちるのでaddを使う
this.addContentView(linearLayout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
Button bt1 = new Button(this);
bt1.setText("ボタン表示");
linearLayout.addView(bt1,new LinearLayout.LayoutParams(300,100));

bt1.setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View v) {
       /*ボタンクリックの処理*/
     }
 });

=補足=

setContentViewを使うと落ちるのでaddContentViewを使います。

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5