Skip to content

๐Ÿ‰ ๊ตฌ๊ธ€์—์„œ ์ œ์‹œํ•œ jetpack ์„ ๊ณต๋ถ€ํ•˜๊ธฐ ์ข‹์€ ์•ฑ 'SunFlower'๋ฅผ ํด๋ก  ์ฝ”๋”ฉํ•œ ๋ ˆํฌ

Notifications You must be signed in to change notification settings

heechokim/sunflower_clone_cording

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

46 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒป ์ดˆํžˆ์˜ SunFlower ํด๋ก  ์ฝ”๋”ฉ ๊ฐœ๋ฐœ์ผ์ง€

SunFlower ์•ฑ์€ Android Jetpack์„ ์ž˜ ์ ์šฉ์‹œํ‚ค๋ฉฐ ์—…๋ฐ์ดํŠธ ์ค‘์ธ android ๊ณต์‹ ์ƒ˜ํ”Œ ์•ฑ์ด๋‹ค.

Jetpack์„ ๊ณต๋ถ€ํ•˜๊ธฐ์— ์ข‹์€ ์•ฑ์ธ ๊ฒƒ ๊ฐ™์•„ ํด๋ก  ์ฝ”๋”ฉํ•ด๋ณด๊ธฐ๋กœ ํ–ˆ๋‹ค!

ํ”„๋กœ์ ํŠธ ํด๋” ๊ตฌ์กฐ

  • MainActivity
    • activity_main.xml
      • Navigation๊ณผ ์—ฐ๊ฒฐ๋œ Fragment ํ•œ ๊ฐœ๊ฐ€ ๋ฐฐ์น˜๋˜์–ด ์žˆ์Œ
    • onCreate()
      • data binding์„ ์‚ฌ์šฉํ•˜์—ฌ activity_main.xml ํŒŒ์ผ์„ binding ํ•จ(ํ™œ์„ฑ ๋ทฐ๋กœ ์„ค์ •)

SunFlower App ํด๋ก  ์ฝ”๋”ฉํ•˜๋ฉด์„œ ๋‚˜์—๊ฒŒ ์ ์šฉํ•˜๋ฉด ์ข‹์€ ๊ฒƒ๋“ค!

1๏ธโƒฃ Build ํŒŒ์ผ์— ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ Dependency ์ž‘์„ฑํ•  ๋•Œ root build.gradle ํŒŒ์ผ์— ๋ฒ„์ „ ์ •๋ฆฌํ•˜๊ณ , app build.gradle ํŒŒ์ผ์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ!

// 1. root build.gradle ํŒŒ์ผ 
buildscript {
    // Define versions in a single place
    ext {
        // Sdk and tools
        compileSdkVersion = 30
        minSdkVersion = 21
        targetSdkVersion = 30

        // App dependencies
        appCompatVersion = '1.1.0'
        constraintLayoutVersion = '2.0.0-beta3'
        ...
    }

    repositories {
        google()
        jcenter()
    }

    ...
}
// 2. app build.gradle ํŒŒ์ผ ์˜ˆ์‹œ
...
dependencies {
    implementation "androidx.appcompat:appcompat:$rootProject.appCompatVersion"
    implementation "androidx.constraintlayout:constraintlayout:$rootProject.constraintLayoutVersion"
    ...
}

2๏ธโƒฃ ๋„ค์ด๋ฐ ์Šคํ‚ฌ!

  • file ์ƒ์„ฑ์‹œ ์ด๋ฆ„ ์ง“๊ธฐ.

    • xml ํŒŒ์ผ์€ activity_main.xml, fragment_detail ์ฒ˜๋Ÿผ activity, fragment๋ฅผ ์•ž์œผ๋กœ ๋ฐฐ์น˜ํ•œ๋‹ค.

    • ํด๋ž˜์Šค ํŒŒ์ผ์€ MainActivity.kt, DetailFragment ์ฒ˜๋Ÿผ ํ•ด๋‹น xml ํŒŒ์ผ ์ด๋ฆ„์˜ ์ˆœ์„œ๋ฅผ ๋ฐ”๊พธ์–ด ํŒŒ์Šค์นผ๋ฒ•์œผ๋กœ ์ž‘์„ฑํ•œ๋‹ค.

  • xml ํŒŒ์ผ์—์„œ ์‚ฌ์šฉํ•˜๋Š” id ๋Š” snake ํ‘œ๊ธฐ๋ฒ•์œผ๋กœ ์ž‘์„ฑํ•˜์ž.

    • fragment์˜ id๋Š”

      <fragment
        android:id="@+id/plant_detail_fragment"
        ...
      >

      plant_detail_fragment ์ฒ˜๋Ÿผ fragment๋ฅผ ๋งจ ๋งˆ์ง€๋ง‰์— ๋ถ™์ธ๋‹ค.

    • layout์˜ id๋Š”

      <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:id="@+id/coordinator_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
         
      ...
      </androidx.coordinatorlayout.widget.CoordinatorLayout>

      coordinator_layout ๊ณผ ๊ฐ™์ด ๋ ˆ์ด์•„์›ƒ์˜ ๊ณ ์œ  ์ด๋ฆ„์œผ๋กœ ์ž‘์„ฑํ•œ๋‹ค. ๋งŒ์•ฝ AppBarLayout์„ ๋ฐฐ์น˜ํ–ˆ๋‹ค๋ฉด id๋Š” app_bar_layout ์œผ๋กœ ์ž‘์„ฑํ•˜๋ผ๋Š” ๊ฒƒ!

  • ํด๋”๋ช…์€ ๋ชจ๋‘ ์†Œ๋ฌธ์ž๋กœ ์ž‘์„ฑํ•˜๊ณ , ํด๋” ์•ˆ์— ์ €์žฅํ•  ํŒŒ์ผ๋“ค์ด ์—ฌ๋Ÿฌ๊ฐœ๋ฉด ํด๋”๋ช… ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰์— s(๋ณต์ˆ˜ํ˜•)๋ฅผ ๋ถ™์ด์ž.

    • Adapter์™€ ๊ด€๋ จ๋œ ํด๋ž˜์Šค๋“ค์ด ์ €์žฅ๋  ํด๋”๋Š” adapters ๋ผ๊ณ  ์ด๋ฆ„ ์ง“๋Š”๋‹ค.

3๏ธโƒฃ width, height ๊ฐ’ ์ž‘์„ฑ ์Šคํ‚ฌ!

  • ์ž์‹ ๋ทฐ๋ฅผ ๊ฐ€์ง€๋Š” ๋ถ€๋ชจ ๋ทฐ์˜ width๋‚˜ height ๊ฐ’์€ wrap_content๋กœ ๋งž์ถฐ์ฃผ์ž. (์ฆ‰, ๋ถ€๋ชจ ๋ทฐ์—์„œ width๋‚˜ height ๋†’์ด๋ฅผ ์ง์ ‘ dp ๊ฐ’์œผ๋กœ ๋„ฃ์ง€ ๋ง์ž๋Š” ๊ฒƒ!)

    <com.google.android.material.appbar.AppBarLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content">
    
      <com.google.android.material.appbar.MaterialToolbar
          android:id="@+id/topAppBar"
          android:layout_width="match_parent"
          android:layout_height="200dp"
                                                          
    </com.google.android.material.appbar.AppBarLayout>

    ์œ„ ์ฝ”๋“œ์—์„œ ๋ถ€๋ชจ ๋ทฐ์ธ AppBarLayout์˜ width๋Š” match_parent๋กœ ๋งž์ท„์ง€๋งŒ(์ž์‹ ๋ทฐ์˜ ํฌ๊ธฐ์— ์˜ํ–ฅ์„ ๋ฐ›์ง€ ์•Š์„ ๋ทฐ์ด๊ธฐ ๋•Œ๋ฌธ) height๋Š” wrap_content๋กœ ๋งž์ถ”์—ˆ๋‹ค.

    ์ž์‹ ๋ทฐ์ธ MaterialToolBar์˜ height๊ฐ€ ์–ธ์ œ๋“ ์ง€ ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ž์‹ ๋ทฐ์˜ ๋†’์ด์— ๋ถ€๋ชจ ๋ทฐ๊ฐ€ ๋™์ ์œผ๋กœ ๋งž์ถฐ์ง€๋„๋ก ํ•œ ๊ฒƒ!

4๏ธโƒฃ ์ฃผ์„ ์ž‘์„ฑ ์Šคํ‚ฌ

  • ์˜์–ด๋กœ ์ž‘์„ฑํ•  ๋•Œ๋Š” ๋™์‚ฌ(์ฒซ ์•ŒํŒŒ๋ฒณ ๋Œ€๋ฌธ์ž)๋กœ ์‹œ์ž‘ํ•˜๊ฒŒ๋” ์ž‘์„ฑํ•œ๋‹ค.

    ์˜ˆ ) // Initialize view objects

    ์˜ˆ ) // Set the icon and text for each tab

SunFlower App ํด๋ก  ์ฝ”๋”ฉํ•˜๋ฉฐ ๊ณต๋ถ€ํ•œ ๊ฒƒ๋“ค

Contributed

Official SunFlower App ์˜ Contributor๊ฐ€ ๋˜์—ˆ๋‹ค!

--> Official SunFlower App์˜ Toolbar ์ด๋ฆ„ ๋ฐ”๊ฟˆ

About

๐Ÿ‰ ๊ตฌ๊ธ€์—์„œ ์ œ์‹œํ•œ jetpack ์„ ๊ณต๋ถ€ํ•˜๊ธฐ ์ข‹์€ ์•ฑ 'SunFlower'๋ฅผ ํด๋ก  ์ฝ”๋”ฉํ•œ ๋ ˆํฌ

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages