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
1
Toast.makeText(this"사스가 토오스트"1).show();
cs

1
2
3
4
5
6
7
8
9
10
        toastBtn.setOnClickListener(new View.OnClickListener() {
            
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(), "토오스트 떳다!"1).show();
                            //메인엑티비티가 멤버함수로(상속받아서) 가지고 있는 저 함수를 불러서
                            // 컨텍스트 객체를 받아오든가
            }
        });
cs

1
2
3
                Toast.makeText(MainActivity.this"토오스트 떳다!"1).show();
                              //이벤트 처리 객체를 가리키는 this가 아닌 
                              //엑티비티를 가리키는 this
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
        chk1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                // TODO Auto-generated method stub
                Toast.makeText(MainActivity.this,
                        buttonView.getText()+"이"+(isChecked ? "선택":"해제")+"되었습니다."0).show();
                if(isChecked)
                    chk2.setChecked(false);
                
                
            }
        });
cs



ViewGroup은 자신 내부에 다른 위젯을 담을 수 있는 컨테이너

자바로 치면 프레임이나 패널 같은 녀석

ViewGrouo은 위젯들의 부모클래스인 View를 멤버로 유지할건데 ViewGroup자체도 View를 상속받음


ViewGroup : 뷰들을 담고있는 그룹, 뷰그룹은 뷰들을 배치하는 역할

다양한 뷰그룹(레이아웃)

- 리니어 레이아웃 : 박스모델, 사각형 영역들을 이용해 화면을 구성

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}" 
    android:orientation="horizontal">
    
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="btn1"
        android:layout_weight="1"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="btn2"
        android:layout_weight="1"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="btn3"
        android:layout_weight="1"/>
 
</LinearLayout>
cs


- 상대 레이아웃  : 규칙기반 모델, 부모컨테이너나 다른 뷰와의 상대적 위치를 이용해 화면을 구성

- 프레임 레이아웃 : 기본단위 모델, 하나의 뷰만 보여줌, 가장 단순하지만 여러개의 뷰를 중첩한 후 각 뷰를 전환하여 보여주는 방식에 유리

- 테이블 레이아웃 : 격자 모델, 격자 모양의 배열을 이용하여 화면을 구성

- 스크롤 뷰 : 스크롤이 가능한 컨테이너, 뷰 또는 뷰그룹이 내부에 담아서 화면영역이 넘어갈때 스크롤 기능 제공


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:gravity="center">
        
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="btn1_1"
            android:layout_gravity="top"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="btn1_2"
            android:layout_gravity="center"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="btn1_3"
            android:layout_gravity="bottom"/>
    </LinearLayout>
    
    
    <Button
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:text="btn4"
        android:layout_weight="1"
        android:gravity="bottom|center"/>
cs




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

Day89 안드로이드 엑티비티 전환  (0) 2016.07.25
Day88  (0) 2016.07.22
Day87  (0) 2016.07.21
Day85 안드로이드 액티비티  (0) 2016.07.19
Day84 안드로이드  (0) 2016.07.18

+ Recent posts