public class DynaLayoutT extends Activity {
TextView tv;
boolean flag = false;
Button b2;
LinearLayout ll2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*
if(flag){
setContentView(R.layout.main);
}else{
setContentView(R.layout.sub);
}*/
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
LayoutParams params1 = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT);
ll.setLayoutParams(params1);
//ll.setBackgroundColor(Color.YELLOW);
TextView TextView01 = new TextView(this);
LayoutParams params2 = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
TextView01.setLayoutParams(params2);
TextView01.setGravity(Gravity.CENTER);
TextView01.setTextSize(TypedValue.COMPLEX_UNIT_PX, 30.0f);
TextView01.setText("동적 레이아웃(어휴~)");
ll.addView(TextView01);
ll2 = new LinearLayout(this);
ll2.setOrientation(LinearLayout.HORIZONTAL);
LayoutParams params3 = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
ll2.setLayoutParams(params3);
//ll2.setBackgroundColor(Color.YELLOW);
ll.addView(ll2);
Button b1 = new Button(this);
LayoutParams params4 = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
b1.setLayoutParams(params4);
b1.setText("버튼1(어휴~)");
ll2.addView(b1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(ll2.getChildCount() == 2){
ll2.removeView(b2);
}else{
ll2.addView(b2, 1);
}
}
});
b2 = new Button(this);
b2.setLayoutParams(params4);
b2.setText("버튼2(어휴~)");
ll2.addView(b2);
setContentView(ll);
}
}
'스마트폰 > 안드로이드' 카테고리의 다른 글
InputOutputStream_1 공부. (0) | 2011.05.13 |
---|---|
다이얼로그박스 공부. (0) | 2011.05.13 |
Toast 토스트 공부. (0) | 2011.05.13 |
Notification 공부. (0) | 2011.05.13 |
명시적 intent 공부. (0) | 2011.05.13 |