1
2
3
4
5
6
7
8
9
setContentView(R.layout.activity_main);
        //해당 xml파일에 있는 요소들을 객체화
        //+
        //객체화 된 뷰를 전체화면으로 설정
        
        
        //xml을 객체화해서 전체화면으로 설정하는 -> setContentView
        
        //xml을 객체화해서 특정 뷰그룹에 집어넣는 역할 -> Layoutinflater
cs


인플레이션 : xml레이아웃에 정의된 내용이 메모리 상에 객체화되는 과정


inflation작업을 수행하는 작업은 LayoutInflater라는 클래스가 수행하고

해당 클래스의 객체는 시스템 서비스로 제공됨

시스템 서비스는 getSystemService메소드를 통해 제공 받을 수 있음

1
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
cs

Activity클래스 안에서라면 이렇게도 얻어올 수 있다.

1
LayoutInflater inflater = getLayoutInflater();
cs


LayoutInflater의 팩토리 메소드 사용해서 얻어올 수도 있다.

1
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
cs


1
2
//person_info.xml을 인플레이션해서 inputFormLayout뷰그룹안에 넣기
inflater.inflate(R.layout.person_info, inputFormLayout);
cs


inflate(xml정보, 뷰그룹) <-  부모로 삼을 뷰그룹 or null 

null일 경우 최상위 layout_xxx 무시

1
2
View view = inflater.inflate(R.layout.person_info, null);
inputFormLayout.addView(view);
cs


inflate(int res, ViewGroup root, boolean attacthToRoot)

res : 레이아웃 xml파일의 id

root : attacthToRoot가 true일 경우 생성되는 뷰가 추가될 부모뷰 attatchToRoot가 false일 경우 해당 레이아웃의 레이아웃파람만 사용, 

        null일 경우 레이아웃파람 무시

attachToRoot : true일 경우 생성되는 뷰를 root의 자식으로 만듬, false일 경우 root는 생성되는 뷰의 레이아웃파람을 생성하는데만 사용


inflate(xml정보, 뷰그룹, t/f)

1
2
View view = inflater.inflate(R.layout.person_info,inputFormLayout, false);
inputFormLayout.addView(view);
cs




' IOT 기반 응용 SW과정 > Android, Arduino' 카테고리의 다른 글

Day93 AlertDialog  (0) 2016.07.29
Day92  (0) 2016.07.28
Day90  (0) 2016.07.26
Day89 안드로이드 엑티비티 전환  (0) 2016.07.25
Day88  (0) 2016.07.22

+ Recent posts