2015년 9월 12일 토요일

프로그래밍 적으로 View 만들어 배치하기

@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 requestWindowFeature(Window.FEATURE_NO_TITLE);
 
 RelativeLayout relativeLayout = new RelativeLayout(this);
 
 RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
   RelativeLayout.LayoutParams.WRAP_CONTENT, 
   RelativeLayout.LayoutParams.WRAP_CONTENT);
 
 params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);

 TextView textView = new TextView(this);
 textView.setText("Hello World");

 relativeLayout.addView(textView, params); 

 setContentView(relativeLayout);
}

댓글 없음:

댓글 쓰기