뷰 소개

UI 구성요소
뷰: UI 구성요소의 기본 클래스이면서 화면을 구성하는 기본 단위. 뷰의 종류로는 버튼, 텍스트뷰, 이미지뷰 같은 위젯과 컨스트레인트 레이아웃, 리니어 레이아웃과 같은 뷰 그룹이 있다.
위젯(뷰): 위젯은 화면에 직접적으로 보이고 사용자와 상호작용하는 구성요소이다. 위젯은 뷰 그룹에 속해야 한다. 텍스트뷰, 버튼, 에디트텍스트 등의 위젯을 통해 사용자의 이벤트를 처리하고 정보를 보여준다. 위젯을 편의상 뷰라고 부른다.
뷰 그룹(레이아웃): 뷰 그룹은 한 개 이상의 뷰 혹은 다른 뷰 그룹을 담고 뷰들을 배치하는 역할을 한다. 그래서 뷰 그룹을 레이아웃이라고도 부른다.
뷰 공통 속성
너비와 높이

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button1"
/>
</LinearLayout>




dp란 무엇인가?
패딩과 마진


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#D7FAEA"
android:text="패딩, 마진 둘 다 없음"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#4B653B"
android:text="패딩, 마진 둘 다 없음"
android:textColor="#FFFFFF"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="#D7FAEA"
android:text="마진만 있음"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="#4B653b"
android:text="마진만 있음"
android:textColor="#ffffff"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#d7faea"
android:padding="10dp"
android:text="패딩만 있음"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#4b653b"
android:padding="10dp"
android:text="패딩만 있음"
android:textColor="#ffffff"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="#d7faea"
android:padding="10dp"
android:text="패딩, 마진 둘 다 있음"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="#4b653b"
android:padding="10dp"
android:text="패딩, 마진 둘 다 있음"
android:textColor="#ffffff"
android:textSize="20sp"/>
</LinearLayout>

텍스트뷰의 기본 속성
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="안녕하세요. 손현수입니다."
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"/>
</LinearLayout>

색상을 지정하는 숫자
dp와 sp의 차이점
strings.xml과 color.xml 사용하기
``kotlin
#FFBB86FC #FF6200EE #FF3700B3 #FF03DAC5 #FF018786 #FF000000 #FFFFFFFF #000000//새로 추가한 메인 컬러 #25a632//새로 추가한 서브 컬러 ```<resources>
<string name="app_name">LearningViews</string>
<string name="greeting">안녕하세요. 손현수입니다.</string>//새로 추가한 인사말 코드
</resources>
미리 지정한 색상과 텍스트 사용해보기
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/greeting"//미리 지정한 텍스트 사용
android:textColor="@color/colorMain"//미리 지정한 색상 사용
android:textSize="20sp"
android:textStyle="bold"/>
</LinearLayout>

이미지뷰
이미지를 리소스에 추가하기
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/sample_image"/>
</LinearLayout>

이미지뷰 비율 조정하기: Scale Type


버튼
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="클릭 해주세요"
android:textColor="#000000"
android:textSize="20sp"/>
</LinearLayout>

에디트텍스트
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello World라고 입력해주세요."
android:padding="10dp"
android:layout_margin="10dp"/>
</LinearLayout>

에디트텍스트의 다양한 속성: 비밀번호, 전화번호, 이메일, 날짜
