출처: https://3months.tistory.com/307 [Deep Play]

안드로이드/연습

[Android] XML 텍스트 색깔 지정 및 위치 조정하기

코딩하는 랄뚜기 2021. 8. 10. 12:27
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="5dp"
    tools:context=".MainActivity">
    <Button
        android:layout_height="60dp"
        android:layout_width="match_parent"
        android:layout_margin="30dp"
        android:textColor="@color/black"
        android:backgroundTint="#4000ff00"
        android:text="버튼 1">
    </Button>
    <TextView
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:hint="여긴 텍스트뷰입니다">
    </TextView>
    <Button
        android:layout_height="40dp"
        android:layout_width="match_parent"
        android:backgroundTint="#2AB2ff"
        android:layout_margin="30dp">
    </Button>
    <Button
        android:layout_marginLeft="30dp"
        android:layout_marginBottom="20dp"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:backgroundTint="#10000000"
        android:text="버튼 2"/>

</LinearLayout>

위젯의 위치를 조정 할 때 padding과 layout_margin의 차이를 알아야 더 확실하게 위치를 조정할 수 있다.

padding은 보통 Layout에 안에서 사용하는데 Layout의 경계선에서 얼마나 위젯을 띄울 것인지 조절해준다. padding만 사용하면 상하좌우 모두 적용이 되기 때문에 따로 지정하고 싶다면 paddingTop, paddingBottom, paddingLeft, paddingRight를 이용하면 된다.

 

padding은 경계선이 위젯들을 밀어내는 개념이라면 layout_margin은 위젯이 다른 위젯을 밀어내는 개념이다.(경계선일 경우 밀린다.)

때문에 layout_margin은 각 위젯 속성으로 지정해주어야 한다. padding과 마찬가지로 layout_margin만 사용하게 되면 상하좌우 모두 적용이 되고 따로 지정하고 싶다면 layout_marginTop, layout_marginBottom, layout_marginLeft, layout_marginRight를 이용하면 된다.

 

레이아웃 혹은 위젯들의 색깔을 정할 때는 background로 지정해주면 된다.(이상하게 내 작업환경에서는 위젯은 backgroundTint만 적용이 된다.) 문자열 #RRGGBB가 들어가서 각각의 값을 잘 조정해주면 된다. #바로 뒤에 숫자를 추가하면 투명도도 조절 할 수 있다.

 

실행 화면

'안드로이드 > 연습' 카테고리의 다른 글

[Android] xml RelativeLayout 2  (0) 2021.08.11
[Android] RelativeLayout 속성  (0) 2021.08.11
[Android] xml layout_weight  (0) 2021.08.11
[Android] 단순한 계산기  (0) 2021.08.10
[Android] 좀 그럴 듯한 앱  (0) 2021.08.10