주먹밥님 안녕하세요~
제 생각에는 커스텀 레이아웃을 사용하셔야 할 것 같네요.
#1
본문에 그리신대로 메인레이아웃에 위젯(버튼과 설명을 표시할)을 세팅하신후,
#2
Linear layout;
layout = (LinearLayout) findViewById (R.id.layout);
위와 같이 메인에 있는 레이아웃을 캐치하세요.
#3
그리고 버튼을 클릭했을 때,
Button bt1 = (Button)findViewById(R.id.button1);
bt1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
layout.removeAllViews(); // 현재 표시된 뷰를 모두 지워주고
layout.addView (lin1); // 커스텀 레이아웃을 add 하여 표시.
}
});
Button bt2 = (Button)findViewById(R.id.button2);
bt2.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
layout.removeAllViews();
layout.addView (lin2);
}
});
#4
#3에서 사용한 layout.addView (클래스); 의 내용은 다음과 같구요
public class Lin01 extends LinearLayout {
TextView tv1;
TextView tv2;
public Lin01 (Context context, AttributeSet attrs) {
super(context, attrs);
onFinishInflate();
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
((Activity) getContext()).getLayoutInflater().inflate(R.layout.test1, this); // 할당할 xml 레이아웃
setupViewItems();
}
private void setupViewItems() { // 할당할 xml 에 붙은 위젯
tv1 = (TextView) findViewById(R.id.textView1);
tv2 = (TextView) findViewById(R.id.textView2);
}
}
#5
아래와 같이 lin1 과 lin2 를 사용하기전에 생성해주면 끗.
lin1 = new Lin01(this, null);
lin2 = new Lin02(this, null);