Android Studio

Android - 사용자 인터페이스 기초 wee3-2(3-1)

Starters 2020. 9. 16. 14:21

XML 파일로 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="vertical"
    >

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="첫번째 버튼">
    </Button>

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="두번째 버튼">
    </Button>

</LinearLayout>

 

match_parent : 부모의 크기를 꽉 채움

wrap_content : 뷰가 나타내는 내용물의 크기에 맞춤

숫자 : 크기를 정확하게 지정

 

안드로이드에서 크기 나타내는 단위

 

색상

불투명 검정 - 0xFF000000

불투명 흰색 - 0xFFFFFFFF

 

그리기

 

margin, padding

 

- 각 위치별 마진 속성

 

 

기본적인 뷰들

TextView

텍스트 뷰의 속성들

Ex)

<?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="vertical"
    >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#0000ff"
        android:text="This is a test"
        android:textColor="#FF0000"
        android:textSize="20pt"
        android:textStyle="italic"
        android:typeface="serif"
        />

</LinearLayout>

 

EditText

- 입력이 가능한 텍스트 필드

- 텍스트 뷰 클래스를 상속받음

- 사용자 입력값을 java코드로 불러와서 사용(처리)하는 것도 가능

 

EditText 속성들

- singleLine 은 defalut가 True -> 따로 설정 안하면, 한줄로만 입력된다.

 

inputType의 종류

+ numberPassword 숫자값을 비밀번호롤 받을 때

 

<?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="vertical"
    >

    <EditText
        android:id="@+id/edit1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="아이디"
        android:inputType="text"
        />

    <EditText
        android:id="@+id/edit2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="패스워드"
        android:inputType="numberPassword"
        />

    <EditText
        android:id="@+id/edit3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="010-XXXX-XXXX"
        android:inputType="phone"
        />

</LinearLayout>

- type에 따라 입력 키보드도 바뀐다.

 

 

 

ImageView

- 아이콘과 같은 간단한 이미지 표시에 사용

 

ImageView 속성들

 

<?xml version="1.0" encoding="utf-8"?>
<ImageView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/icon"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="true"
    android:src="@drawable/starters"
    />

-> src 에 이미지 파일의 확장자명은 쓰지 않아도됨