기록

Part1_Ch02_03 숫자세기 UI 그리기 (1) 본문

안드로이드 앱(Kotlin|Java)/[2025~] 안드로이드 앱

Part1_Ch02_03 숫자세기 UI 그리기 (1)

heylo 2025. 2. 3. 14:23

Layout

viewGrop 이라는 아주 큰 도화지 아래에

작은 도화지 그룹인 viewGrop 이 있고

그림요소인 View 들이 각각에 존재한다-고 생각할 수 있다.

 

Palette 에서 요소 Drag & Drop 할 수 있음

 

 

app > res > layout > activity_main.xml

리소스 폴더 (res) : 화면을 그리기 위한 다양한 요소들이 있는 폴더

 

0) activity_main.xml

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

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:srcCompat="@tools:sample/avatars" />



    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

 

1) LinearLayout 설정

<LinearLayout

 

 

2) match_parent 와 wrap_content

부모뷰의 크기에 맞추기 : match_parent

android:layout_width="match_parent"
android:layout_height="match_parent"

요소 크기에 맞추기 : wrap_content

android:layout_width="wrap_content"
android:layout_height="wrap_content"

 

 

3) orientation

요소들을 세로로 쌓으려면

android:orientation="**vertical**"

요소들을 가로로 쌓으려면

android:orientation="**horizontal**"

 

 

4) 만약

위 코드에서 orientation 을 horizontal 로 바꾼다면

android:orientation="horizontal"

세로로 쌓이던 요소가 가로로 쌓인다.

Textview 에서 layout_width가 match_parent 였으므로

Textview 오른쪽에 붙을 Button 요소는

화면에 보이지 않는다.

layout_width 를 wrap_content 로 변경한다면

요소의 크기만큼 가로길이가 지정된다.

Text 길이만큼.