Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

はじめに

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を使います。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした