'소스에서 margin 주기'에 해당되는 글 1건

  1. 2011.06.15 [안드로이드] 소스에서 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);

}

}

Posted by 예배하는 프로그래머