[안드로이드] 소스에서 layout 셋팅해주기
public class margin_test{
@Override
public void onCreate(Bundle savedInstanceState){
LinearLayout linear = new
LinearLayout(this);
linear.setOrientation(LinearLayout.VERTICAL);
linear.setBackgroundColor(Color.LTGRAY);
Button btn = new Button(this);
btn.setText("Button");
LinearLayout.LayoutParams parambtn = new
LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.FILL_PARENT);
parambtn.setMargins(0,
50, 0, 50);
linear.addView(btn, parambtn);
setContentView(linear);
}
}
public class LinearLayout_Test{
@Override
public void onCreate(Bundle savedInstanceState){
LinearLayout linear = new
LinearLayout(this);
linear.setOrientation(LinearLayout.VERTICAL);
linear.setGravity(Gravity.CENTER);
linear.setBackgroundColor(Color.LTGRAY);
TextView text = new
TextView(this);
text.setText("TextView");
text.setTextSize(20);
text.setBackgroundColor(Color.GREEN);
LinearLayout.LayoutParams paramtext = new
LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
linear.addView(text,
paramtext);
setContentView(linear);
}
}