-여백
안드로이드에서 Layout의 여백을 설정하기 위해 사용하는 코드는 Margin 과 padding이 있습니다
Margin : 위젯과 Layout 사이의 공간을 설정
padding : 위젯 안에서 실제 내용과 위젯의 경계 사이의 공간 설정
코드 사용
Margin >> android:layout_margin =
padding >> android:padding =
예) android:layout_marginTop ="20dp" >> 위젯과 레이아웃 윗부분의 사이의 공간을 20dp 로 설정
android:paddingRight = "20dp" >> 실제 내용(텍스트, 이미지, 등) 과 위젯의 오른쪽 사이의 공간을 20 dp로 설정
-정렬Layout내 에서 위젯이 배치 될때 사용하는 코드는 gravity입니다
gravity = Layout 내에서 자식 위젯이 정렬되는 위치 변경
gravity에 사용되는 값으로는
top : layout 안에서 위쪽에 위치
bottom : layout 안에서 아래쪽에 위치
left : layout 안에서 왼쪽에 위치
right : layout 안에서 오른쪽에 위치
center : layout 안에서 가운데에 위치
center_horizontal : 가로를 기준으로 가운데에 위치
center_vertical : 세로를 기준으로 가운데에 위치
fill : 가로, 세로 방향으로 가득 채움
fill_horizontal : 가로 방향으로 가득 채움
fill_vertical : 세로 방향으로 가득 채움
start : layout 안에서 시작하는 위치에 정렬
end : layout 안에서 끝나는 위치에 정렬
등이 있습니다
*위의 코드는 | 를 통해 혼합하여 사용할 수 있습니다
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="#ff0000"
android:text="start"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#00ff00"
android:text="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#0000ff"
android:text="center_horizontal"
/>
</LinearLayout>
*gravity와 Layout_gravity의 차이점
gravity : 위젯 안에서 실제 내용의 위치를 정렬
Layout_gravity : 레이아웃 안에서 위젯의 위치를 정렬
'Android' 카테고리의 다른 글
Android] Button 클릭 시 화면 전환(Intent사용) (0) | 2022.01.12 |
---|---|
Andriod] Constraintlayout 정렬 (0) | 2022.01.11 |
Andriod]4대 컴포넌트 (0) | 2022.01.07 |
Android] Manifest (0) | 2022.01.07 |
Android] Layout 기초 (0) | 2022.01.04 |