Learn & Record

[FastCampus] Android (Layout, LinearLayout, TextView, Activity) 본문

Dev/Android

[FastCampus] Android (Layout, LinearLayout, TextView, Activity)

Walker_ 2024. 2. 16. 22:09

1. Layout 

 - 레이아웃은 앱에서 사용자 인터페이스를 위한 구조를 정의합니다.

 - 레이아웃의 모든 요소는 View와 ViewGroup객체의 계층 구조를 사용하여 빌드됩니다.

 - View 객체는 일반적으로 '위젯'이라고 하고 Button 또는 TextView와 같은 여러 서브클래스 중 하나일 수 있습니다.

 - UI 요소를 XML로 선언. 및 아이콘 사용

 

 

2. LinearLayout

 - match_parent : 부모 요소 기준으로 길이, 높이를 맞춘다.

 - wrat_content : 내용을 감싸는 정도, 내부 콘텐츠의 크기에 전체를 맞춘다.

 - orientation : 정한 방향대로 선형 구조를 그린다. (vertical, horizontal)

 - layout_gravity : 부모 뷰를 기준으로 정렬

 - gravity : 뷰 자신을 기준으로 정렬

 - layout_weught : 상대적 비율로 크기를 조절한다

 - layout_margin : 부모 뷰로 부터 지정한 폭을 띄운다

 - layout_padding : 컨텐츠 자신의 원래 위치로 부터 지정한 폭을 띄운다

 

3. TextView

 - Text : 텍스트뷰에 보일 텍스트를 입력가능하다

 - TextSize : 작성한 텍스트의 사이즈를 설정할 수 있다.

 - TextColor : 작성한 텍스트의 색상을 지정할 수 있다.

 - textStyle : 텍스트 스타일 지정 가능 (bold, italic ... 등) | 를 통해 동시 지정 가능

 

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat 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"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/numberTextView"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:text="100"
        android:textSize="100dp"
        android:textColor="@color/teal_200"
        android:textStyle="bold|italic"
        android:gravity="center" />

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

        <Button
            android:id="@+id/resetButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="초기화"
            android:layout_marginTop="16dp"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"
            />

        <Button
            android:id="@+id/plusButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_margin="16dp"
            android:text="+"/>

    </LinearLayout>



</androidx.appcompat.widget.LinearLayoutCompat>

 

4. Activity 

 - 앱을 구성하는 기본 요소 중 하나입니다.

 - 사용자가 앱과 상호작용하기 위한 진입점 역할을 하며 사용자가 앱 내에서 (뒤로 버튼으로) 탐색하거나 앱 간 이동 버튼의 중심

 - id : XML에 android:id 로 id 값을 각 기능에 지정 

 - findViewById : XML의 UI 요소를 변수로 지정하고 기능설정

 - setOnClickListener : findViewById로 불러온 XML의 UI 버튼 요소에 기능 설정

 - var : 변경이 가능한 변수

 - val : 변경이 불가능한 변수

package com.example.androidup

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.TextView

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val numberTextView = findViewById<TextView>(R.id.numberTextView)
        val resetButton = findViewById<Button>(R.id.resetButton)
        val plusButton = findViewById<Button>(R.id.plusButton)

        var number = 0

        resetButton.setOnClickListener {
            number = 0
            numberTextView.text = number.toString()
        }

        plusButton.setOnClickListener {
            number += 1
            numberTextView.text = number.toString()
        }
    }
}

 

 

FastCampus 강의 : https://fastcampus.co.kr/dev_online_androidappfinal

 

35개 프로젝트로 배우는 Android 앱 개발 feat. Jetpack Compose 초격차 패키지 Online. | 패스트캠퍼스

35개 프로젝트로 학습하는 '안드로이드 앱 개발의 모든것'. 입문자부터 실무자까지 아우르는 101시간의 풍부한 커리큘럼을 통해 무한한 성장 뿐 아니라 원하는 기업으로의 이직에 성공하세요.

fastcampus.co.kr