공부/Kotlin

[안드로이드] 로그인 화면 구현 연습

ompeom 2020. 8. 28. 18:13

<?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="15dp"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="240dp"
            android:layout_height="120dp"
            android:src="@drawable/pepper"/>
    </LinearLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="아이디"
        android:textSize="20sp"/>
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="이메일 형식"
        android:inputType="textEmailAddress"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="비밀번호"
        android:textSize="20sp"/>
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="비밀번호 입력"/>

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="자동 로그인"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="회원가입"/>
        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="로그인" />
    </LinearLayout>
</LinearLayout>

 

 

 

이메일 방식의 아이디 입력을 원할 때, inputType = textEmailAddress로 해준다면

사용자의 키패드 아래에 @로 바뀐다.

 

기존 키패드 vs 이메일 입력 타입 키패드

 

회원가입 / 로그인 버튼처럼 맨 아래로 내리고 싶을 때 사용하는 방법

가운데에 투명한 TextView를 넣어 버튼을 아래로 밀어버린다.

weight = 1의 의미는 화면에서 다 쓰고 남은 공간의 비중을 100으로 차지하겠다는 뜻이다.

 

height = 0

weight = 1