LayoutInflater로 레이아웃 교체하기

레이아웃 전체를 교체하거나 부분을 교체할때 LayoutInflater로 교체를 할 수 있다.
사용 방법은 주석으로 잘달아 놨으니... 걍 저렇게 쓰면 된다.

1
2
3
4
5
6
7
// activity_main.xml에서 정의한 LinearLayout 할당
LinearLayout inflated = (LinearLayout)findViewById(R.id.changed_layout);
// LayoutInflater 객체 생성
LayoutInflater inflater =  (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// Inflated_Layout.xml로 구성한 레이아웃을 inflated영역(R.id.changed_layout)으로 교체
inflater.inflate(R.layout.new_layout, inflated);
 


Posted by duehd88
,