둘째마당 01
뷰
개념
- 뷰 (View)
- 컨트롤이나 위젯으로 불리는 UI 구성요소
- 사용자의 눈에 보이는 화면의 구성요소들
- 뷰그룹 (View Group)
- 여러 개의 뷰 포함하고 있으며, 뷰그룹 내 뷰의 위치 지정 가능
- 상속 (Inheritance)
- 뷰가 뷰그룹 상속한다면, 뷰그룹 내 또 다른 뷰그룹 가질 수 있음
- 다른 뷰 상속받는다면, 상속받은 뷰의 특성 그대로 가질 수 있음
- 위젯 (Widget)
- 일반적인 컨트롤 역할
- 레이아웃 (Layout)
- 뷰그룹 중 내부에 뷰 포함하며 배치하는 역할
속성
- 뷰의 크기
- android:layout_height="wrap_content"
- android:layout_width="match_parent"
- 뷰의 위치
- android:layout_marginTop: 뷰 위쪽 얼마나 띄울지 지정
- android:layout_marginBottom
- android:layout_marginLeft
- android:layout_marginRight
- android:layout_margin: 위, 아래, 왼쪽, 오른쪽 한꺼번에 얼마나 띄울지 지정
- 태그의 속성
- xmlns:android: 안드로이드 기본 SDK에 포함되어 있는 속성 사용
- android:id 속성의 용도
- XML 레이아웃 파일 내에서 뷰 구분하는 경우
- XML 레이아웃 파일에서 정의한 뷰를 자바 소스 파일에서 찾는 경우
- android:orientation: Guideline의 필수 속성
- = "vertical"
- = "horizontal"
- android:id 속성의 용도
- xmlns:app: 프로젝트에서 사용하는 외부 라이브러리에 포함되어 있는 속성 사용
- app:layout_constraint뷰의 연결점_타깃의 연결점="@+id/아이디값"
- app:layout_constraintTop_toTopOf="@+id/button"
- app:layout_constraintTop_toBottomOf="@+id/button"
- app:layout_constraintBottom_toTopOf="@+id/button"
- app:layout_constraintBottom_toBottomOf="@+id/button"
- app:layout_constraintLeft_toTopOf="@+id/button"
- app:layout_constraintLeft_toBottomOf="@+id/button"
- app:layout_constraintLeft_toLeftOf="@+id/button"
- app:layout_constraintLeft_toRightOf="@+id/button"
- app:layout_constraintRight_toTopOf="@+id/button"
- app:layout_constraintRight_toBottomOf="@+id/button"
- app:layout_constraintRight_toLeftOf="@+id/button"
- app:layout_constraintRight_toRightOf="@+id/button"
- app:layout_constraintGuide_begin="100dp": 위쪽, 왼쪽부터의 거리 지정
- app:layout_constraintGuide_end="100dp": 아래쪽, 오른쪽부터의 거리 지정
- app:layout_constraintGuide_percent="5%": 위쪽, 왼쪽부터의 거리 %단위로 지정
- app:layout_constraint뷰의 연결점_타깃의 연결점="@+id/아이디값"
- xmlns:tools: 화면에 보여줄 때 사용; 안드로이드 스튜디오에서만 적용
- xmlns:android: 안드로이드 기본 SDK에 포함되어 있는 속성 사용
값
- 뷰의 크기
- wrap_content: 뷰 내용물 크기에 자동 맞춤
- match_parent: 뷰 담고 있는 뷰그룹 여유공간 꽉 채움
- 숫자로 크기 지정: dp or px 단위 필요
- 뷰에는 dp
- 글자는 sp
레이아웃
안드로이드 스튜디오에서는 기본 레이아웃이 제약 레이아웃 (Constraint Layout)
제약조건
- 뷰의 연결점과 대상을 연결하며, 뷰와 레이아웃 내 요소와 어떻게 연결되는지 알려줌
- 연결점
- Top, Bottom, Left(Start), Right(End)
- CenterX, CenterY
- Baseline
- 타깃
- 같은 부모 레이아웃 내 다른 뷰의 연결점
- 부모 레이아웃의 연결점
- Guideline
- 여러 개의 뷰를 일정한 기준 선에 정렬할 때 사용
- 화면 배치 위해 추가되지만, 실제 화면의 구성요소는 아님
'Android ᙏ̤̫͚ > Android Programming' 카테고리의 다른 글
[Do it 안드로이드 프로그래밍] 둘째마당 03-1. 기본 위젯 (0) | 2021.07.17 |
---|---|
[Do it 안드로이드 프로그래밍] 둘째마당 02. 레이아웃 (0) | 2021.07.08 |
[Android] chapter 2 - 1 스크롤뷰 사용하기 (0) | 2021.02.27 |
[Android] chapter 1 - 8 드로어블 만들기 (0) | 2021.02.27 |
[Android] chapter 1 - 7 기본 위젯들 (0) | 2021.02.27 |