20160815

LinerLayout.LayoutParams 

 

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;

public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
setContentView(linearLayout);
//LinearLayout.LayoutParams クラスのインスタンスlayoutparamsを作成
final LinearLayout.LayoutParams layoutparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutparams.height=500;

Button button1 = new Button(this);
//setLayoutParamsメッソドでlayoutparamsをセットする
button1.setLayoutParams(layoutparams);
button1.setText("button1");
linearLayout.addView(button1);

Button button2 = new Button(this);
button2.setText("button2");
linearLayout.addView(button2);
}
}

 

 

20160814

 

LinerLayout

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;

public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
setContentView(linearLayout);

Button button1 = new Button(this);
button1.setText("button1");
linearLayout.addView(button1);

Button button2 = new Button(this);
button2.setText("button2");
linearLayout.addView(button2);
}
}