* Layout에 다른 Layout넣기 *
1. 화면 전체에 나타낼 Layout을 메모리 상에 객체화할 때는 setContentView()를 사용한다.
2. 화면 일부만 별로 Layout을 메모리 상에 객체화 하려면 별도 인플레이션 객체를 사용해야 된다.
안드로이드에서는 LayoutInflater 클래스를 이용한다.
이 클래스는 시스템 서비스로 제공되므로 getsystemService(Context.LAYOUT_INFLATER_SERVICE) 메소드를 사용하여
객체를 참조한 후 사용해야 한다.
3. 아래 소스중 activity_main.xml 에서 보면 ["@+id/contentsLayout"] id인 LinearLayout에 위치에 별도 Layout을 넣게 된다.
[ activity_main.xml ]
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
[ button.xml ]
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
[ MainActivity.java ]
/** //이것은 contentsLayout을 부모 컨테이너로 하여 buttons.xml파일에 정의된 레이아우승ㄹ 추가하라는 의미이다. inflater.inflate(R.layout.button, contentsLayout, true); |
'[Android] - 개념 > Layout' 카테고리의 다른 글
Layout에서 별도 Layout 띄우기 (0) | 2016.12.04 |
---|