#17 안드로이드 스튜디오로 안드로이드 앱 만들기 - 주소록 앱의 새 연락처 화면 만들어보기

2018. 2. 2. 17:56안드로이드

반응형

#12 안드로이드 스튜디오로 안드로이드 앱 만들기 - 다양한 사용자 알림 효과 : 토스트(Toast), 다이얼로그(Dialog)

#13 안드로이드 스튜디오로 안드로이드 앱 만들기 - 사용자 이벤트 처리 : 델리게이션 이벤트 모델(Delegation Event Model)

#14 안드로이드 스튜디오로 안드로이드 앱 만들기 - 사용자 이벤트 처리 : 하이어라키 이벤트 모델(Hierarchy Event Model)

#15 안드로이드 스튜디오로 안드로이드 앱 만들기 - 페이스북 메신저 인트로(Facebook messenget intro) 화면 만들어보기

#16 안드로이드 스튜디오로 안드로이드 앱 만들기 - 브런치(brunch) 앱의 새 글 작성 화면 만들어보기




위와 같이 주소록앱의 새연락처 추가 화면을 만들어보자. 화면에 대한 요구사항은 다음과 같다.


■ 사용자 인터페이스

상단에 이미지를 가로 방향 전체를 차지하게 출력하고, 4개의 EditText와 3개의 Image는 세로 방향 정렬을 맞춘다.


■ 화면 스크롤

입력을 위해 키보드가 올라오면 화면이 일부분 가려지는데 이때 사용자가 세로 방향 스크롤을 할 수있게 한다.


■ 키보드 출력 모드 제어

키보드가 올라오면 기본 문자 입력 모드로 올라오는데, 전화 입력은 전화번호 모드, 이메일 입력은 이메일 모드로 키보드가 올라오게 한다.




위 화면을 만들기 위해 필요한 기술은 다음과 같다. 역시나 기본적인 것들이다.

■ 레이아웃 구성

■ 화면 스크롤

■ 키보드 모드 제어










그럼 이제 만들어보자

최종적으로 우리가 만들 파일들은 위 화면과 같다.



Step 1_ 모듈 생성

"phonebook"이라는 이름으로 모듈을 하나 만들자.


Step 2_ 이미지 리소스(Image resource) 준비



Step 3_ activity_main.xml 작성

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
 
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="centerCrop"
                android:src="@drawable/icon_person_large"/>
 
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:layout_marginTop="16dp">
 
                <ImageView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:layout_gravity="center"
                    android:maxWidth="25dp"
                    android:maxHeight="25dp"
                    android:adjustViewBounds="true"
                    android:src="@drawable/icon_person_small"  />
 
                <EditText
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="4"
                    android:inputType="text"
                    android:hint="성"/>
            </LinearLayout>
 
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:layout_marginTop="16dp">
 
                <View
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:layout_weight="1"  />
 
                <EditText
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="4"
                    android:inputType="text"
                    android:hint="이름"/>
            </LinearLayout>
 
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:layout_marginTop="16dp">
 
                <ImageView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:layout_gravity="center"
                    android:maxWidth="25dp"
                    android:maxHeight="25dp"
                    android:adjustViewBounds="true"
                    android:src="@drawable/icon_phone"  />
 
                <EditText
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="4"
                    android:inputType="phone"
                    android:hint="전화"/>
            </LinearLayout>
 
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:layout_marginTop="16dp">
 
                <ImageView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:layout_gravity="center"
                    android:maxWidth="25dp"
                    android:maxHeight="25dp"
                    android:adjustViewBounds="true"
                    android:src="@drawable/icon_email"  />
 
                <EditText
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="4"
                    android:inputType="textEmailAddress"
                    android:hint="이메일"/>
            </LinearLayout>
 
        </LinearLayout>
 
</ScrollView>
 
cs


Step 4_ MainActivity.java 작성

그냥 그대로 두면 된다.


Step 5_ 완성



반응형