{"id":45782,"date":"2021-11-24T13:54:23","date_gmt":"2021-11-24T04:54:23","guid":{"rendered":"https:\/\/www.charlezz.com\/?p=45782"},"modified":"2021-11-24T13:54:24","modified_gmt":"2021-11-24T04:54:24","slug":"migrating-to-jetpack-compose-%eb%8d%94-%eb%a7%8e%ec%9d%80-xml-%ec%bd%94%eb%93%9c-%eb%a7%88%ec%9d%b4%ea%b7%b8%eb%a0%88%ec%9d%b4%ec%85%98-%ed%95%98%ea%b8%b0","status":"publish","type":"post","link":"https:\/\/charlezz.com\/?p=45782","title":{"rendered":"Migrating to Jetpack Compose &#8211; \ub354 \ub9ce\uc740 XML \ucf54\ub4dc \ub9c8\uc774\uadf8\ub808\uc774\uc158 \ud558\uae30"},"content":{"rendered":"\n<p>\uc774\uc81c UI\uc5d0\uc11c \ub204\ub77d\ub41c \uc0ac\ud56d\uc778 \ubb3c\uc8fc\uae30 \uc815\ubcf4 \ubc0f \uc2dd\ubb3c \uc124\uba85\uc758 \ub9c8\uc774\uadf8\ub808\uc774\uc158\uc744 \uc644\ub8cc\ud558\ub294 \uac83\uc774 \ub354 \uc26c\uc6cc\uc84c\ub2e4. \uc774\uc804\uc5d0 \uc218\ud589\ud55c XML \ucf54\ub4dc \uc811\uadfc \ubc29\uc2dd\uc744 \ub3d9\uc77c\ud558\uac8c \uc0b4\ud3b4\ubcf4\uba74, \uc774\ubbf8 \ub098\uba38\uc9c0 \ud654\uba74\uc744 \ub9c8\uc774\uadf8\ub808\uc774\uc158 \ud560 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<p>fragment_plant_detail.xml\uc5d0\uc11c \uc774\uc804\uc5d0 \uc81c\uac70\ud55c \ubb3c\uc8fc\uae30 \uc815\ubcf4 XML \ucf54\ub4dc\ub294 ID\uac00 plant_watering_header \ubc0f plant_watering\uc778 \ub450 \uac1c\uc758 TextView\ub85c \uad6c\uc131\ub41c\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;TextView\n\u00a0 \u00a0 android:id=\"@+id\/plant_watering_header\"\n\u00a0 \u00a0 ...\n\u00a0 \u00a0 android:layout_marginStart=\"@dimen\/margin_small\"\n\u00a0 \u00a0 android:layout_marginTop=\"@dimen\/margin_normal\"\n\u00a0 \u00a0 android:layout_marginEnd=\"@dimen\/margin_small\"\n\u00a0 \u00a0 android:gravity=\"center_horizontal\"\n\u00a0 \u00a0 android:text=\"@string\/watering_needs_prefix\"\n\u00a0 \u00a0 android:textColor=\"?attr\/colorAccent\"\n\u00a0 \u00a0 android:textStyle=\"bold\"\n\u00a0 \u00a0 ... \/>\n\n&lt;TextView\n\u00a0 \u00a0 android:id=\"@+id\/plant_watering\"\n\u00a0 \u00a0 ...\n\u00a0 \u00a0 android:layout_marginStart=\"@dimen\/margin_small\"\n\u00a0 \u00a0 android:layout_marginEnd=\"@dimen\/margin_small\"\n\u00a0 \u00a0 android:gravity=\"center_horizontal\"\n\u00a0 \u00a0 app:wateringText=\"@{viewModel.plant.wateringInterval}\"\n\u00a0 \u00a0 ...\/><\/code><\/pre>\n\n\n\n<p>\uc774\uc804\uc5d0 \ud588\ub358 \uc791\uc5c5\uacfc \uc720\uc0ac\ud558\uac8c PlantWatering\uc774\ub77c\ub294 \uc0c8 \ucef4\ud3ec\uc800\ube14\uc744 \ub9cc\ub4e4\uace0 \ud14d\uc2a4\ud2b8\ub97c \ucd94\uac00\ud558\uc5ec \ud654\uba74\uc5d0 \ubb3c\uc8fc\uae30 \uc815\ubcf4\ub97c \ud45c\uc2dc\ud558\uc790.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">PlantDetailDescription.kt<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>@Composable\nprivate fun PlantWatering(wateringInterval: Int) {\n\u00a0 \u00a0 Column(Modifier.fillMaxWidth()) {\n\u00a0 \u00a0 \u00a0 \u00a0 \/\/ \ub450 Text\uc5d0 \uac19\uc740 modifier\uac00 \uc0ac\uc6a9\ub41c\ub2e4.\n\u00a0 \u00a0 \u00a0 \u00a0 val centerWithPaddingModifier = Modifier\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .padding(horizontal = dimensionResource(R.dimen.margin_small))\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .align(Alignment.CenterHorizontally)\n\n\u00a0 \u00a0 \u00a0 \u00a0 val normalPadding = dimensionResource(R.dimen.margin_normal)\n\n\u00a0 \u00a0 \u00a0 \u00a0 Text(\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 text = stringResource(R.string.watering_needs_prefix),\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 color = MaterialTheme.colors.primaryVariant,\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 fontWeight = FontWeight.Bold,\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 modifier = centerWithPaddingModifier.padding(top = normalPadding)\n\u00a0 \u00a0 \u00a0 \u00a0 )\n\n\u00a0 \u00a0 \u00a0 \u00a0 val wateringIntervalText = LocalContext.current.resources.getQuantityString(\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 R.plurals.watering_needs_suffix, wateringInterval, wateringInterval\n\u00a0 \u00a0 \u00a0 \u00a0 )\n\u00a0 \u00a0 \u00a0 \u00a0 Text(\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 text = wateringIntervalText,\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 modifier = centerWithPaddingModifier.padding(bottom = normalPadding)\n\u00a0 \u00a0 \u00a0 \u00a0 )\n\u00a0 \u00a0 }\n}\n\n@Preview\n@Composable\nprivate fun PlantWateringPreview() {\n\u00a0 \u00a0 MaterialTheme {\n\u00a0 \u00a0 \u00a0 \u00a0 PlantWatering(7)\n\u00a0 \u00a0 }\n}<\/code><\/pre>\n\n\n\n<p>\ubbf8\ub9ac\ubcf4\uae30\ub85c \ubcf4\uba74 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/developer.android.com\/codelabs\/jetpack-compose-migration\/img\/741b92db42c262df.png\" alt=\"741b92db42c262df.png\"\/><\/figure>\n\n\n\n<p>\uba87\uac00\uc9c0 \uc54c\uc544\uc57c \ud560 \uac83\ub4e4\uc774 \uc788\ub2e4.<\/p>\n\n\n\n<ul><li>Text \ucef4\ud3ec\uc800\ube14\uc5d0\uc11c \uc218\ud3c9 \ud328\ub529(horizontal padding) \ubc0f \uc815\ub82c(align) \uac19\uc740 \ub370\ucf54\ub808\uc774\uc158\uc744 \uacf5\uc720\ud558\ubbc0\ub85c, Modifier\ub97c \ub85c\uceec \ubcc0\uc218(\uc608: centerWithPaddingModifier)\uc5d0 \ud560\ub2f9\ud558\uc5ec Modifier\ub97c \uc7ac\uc0ac\uc6a9\ud560 \uc218 \uc788\ub2e4. Modifier\ub294 \uc77c\ubc18 Kotlin \uac1d\uccb4\uc774\ubbc0\ub85c \uadf8\ub807\uac8c \ud560 \uc218 \uc788\ub2e4.<\/li><li>\ucef4\ud3ec\uc988\uc758 MaterialTheme\ub294 plant_watering_header\uc5d0 \uc0ac\uc6a9\ub41c colorAccent\uc640 \uc815\ud655\ud788 \uc77c\uce58\ud558\uc9c0 \uc54a\ub294\ub2e4. \uc9c0\uae08\uc740 \ud14c\ub9c8 \uc139\uc158\uc5d0\uc11c \uac1c\uc120\ud560 MaterialTheme.colors.primaryVariant\ub97c \uc0ac\uc6a9\ud558\uaca0\ub2e4.<\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote\"><p><strong>Warning<\/strong>: \ucef4\ud3ec\uc988\uc758 \ud604\uc7ac \ubc84\uc804\uc5d0\uc11c\ub294 dimension\uc5d0\uc11c \uc218\ub7c9\ud654\ub41c \ubb38\uc790\uc5f4\uc744 \uac00\uc838\uc624\ub294 \uac83\uc744 \uc9c0\uc6d0\ud558\uc9c0 \uc54a\ub294\ub2e4. \uadf8\ub807\uae30 \ub54c\ubb38\uc5d0 LocalContext.current.resources\ub97c \ud1b5\ud574 \uc561\uc138\uc2a4\ud574\uc57c \ud55c\ub2e4. \ud574\ub2f9 \ub0b4\uc6a9\uc740 \uc774\ubbf8 <a href=\"https:\/\/issuetracker.google.com\/158065051\">\uc774\uc288 \ud2b8\ub798\ucee4<\/a>\uc5d0 \ub4f1\ub85d \ub41c \uc0c1\ud0dc\ub2e4.<\/p><p>\uac04\ub2e8\ud558\uac8c \ud558\uae30 \uc704\ud574, \ud568\uc218\ub97c \uc778\ub77c\uc778\uc73c\ub85c \ud638\ucd9c\ud588\uc9c0\ub9cc \uc571\uc5d0\uc11c \uc774 \uc791\uc5c5\uc744 \uc218\ud589\ud558\ub294 \uacbd\uc6b0 \uc7ac\uc0ac\uc6a9\ud560 \uc218 \uc788\ub3c4\ub85d \ub2e4\ub978 \ud568\uc218\ub85c \ucd94\ucd9c\ud55c\ub2e4.<\/p><\/blockquote>\n\n\n\n<p>\ubaa8\ub4e0 UI\uc870\uac01\ub4e4\uc744 \ud568\uaed8 \uc5f0\uacb0\ud558\uace0, PlantDetailContent\uc5d0\uc11c\ub3c4 PlantWatering\uc744 \ud638\ucd9c\ud574 \ubcf4\ub3c4\ub85d \ud55c\ub2e4. \ucc98\uc74c\uc5d0 \uc81c\uac70\ud55c ConstraintLayout XML \ucf54\ub4dc\uc5d0\ub294 Compose \ucf54\ub4dc\uc5d0 \ud3ec\ud568\ud574\uc57c \ud558\ub294 16.dp\uc758 \uc5ec\ubc31\uc774 \uc788\uc5c8\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;androidx.constraintlayout.widget.ConstraintLayout<br>&nbsp; &nbsp; android:layout_width=\"match_parent\"<br>&nbsp; &nbsp; android:layout_height=\"match_parent\"<br>&nbsp; &nbsp; android:layout_margin=\"@dimen\/margin_normal\"&gt;<\/code><\/pre>\n\n\n\n<p>PlantDetailContent\uc5d0\uc11c \uc774\ub984\uacfc \ubb3c\uc8fc\uae30 \uc815\ubcf4\ub97c \ud568\uaed8 \ud45c\uc2dc\ud558\ub294 Column\uc744 \ub9cc\ub4e4\uace0, \uc774\ub97c \ud328\ub529\uc73c\ub85c \uc0ac\uc6a9\ud55c\ub2e4. \ub610\ud55c \ubc30\uacbd\uc0c9\uacfc \uc0ac\uc6a9\ub41c \ud14d\uc2a4\ud2b8 \uc0c9\uc0c1\uc774 \uc801\uc808\ud558\ub3c4\ub85d \uc774\ub97c \ucc98\ub9ac\ud560 Surface\ub97c \ucd94\uac00\ud558\uc790.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">PlantDetailDescription.kt<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>@Composable<br>fun PlantDetailContent(plant: Plant) {<br>&nbsp; &nbsp; Surface {<br>&nbsp; &nbsp; &nbsp; &nbsp; Column(Modifier.padding(dimensionResource(R.dimen.margin_normal))) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PlantName(plant.name)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PlantWatering(plant.wateringInterval)<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<p>\ubbf8\ub9ac\ubcf4\uae30\ub97c \uc0c8\ub85c\uace0\uce68\ud558\uba74 \ub2e4\uc74c\uacfc \uac19\uc740 \ub0b4\uc6a9\uc744 \ubcfc \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/developer.android.com\/codelabs\/jetpack-compose-migration\/img\/97f35931b72c29b.png\" alt=\"97f35931b72c29b.png\"\/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uc774\uc81c UI\uc5d0\uc11c \ub204\ub77d\ub41c \uc0ac\ud56d\uc778 \ubb3c\uc8fc\uae30 \uc815\ubcf4 \ubc0f \uc2dd\ubb3c \uc124\uba85\uc758 \ub9c8\uc774\uadf8\ub808\uc774\uc158\uc744 \uc644\ub8cc\ud558\ub294 \uac83\uc774 \ub354 \uc26c\uc6cc\uc84c\ub2e4. \uc774\uc804\uc5d0 \uc218\ud589\ud55c XML \ucf54\ub4dc \uc811\uadfc \ubc29\uc2dd\uc744 \ub3d9\uc77c\ud558\uac8c \uc0b4\ud3b4\ubcf4\uba74, \uc774\ubbf8 \ub098\uba38\uc9c0 \ud654\uba74\uc744 \ub9c8\uc774\uadf8\ub808\uc774\uc158 \ud560 \uc218 \uc788\ub2e4. fragment_plant_detail.xml\uc5d0\uc11c \uc774\uc804\uc5d0 \uc81c\uac70\ud55c \ubb3c\uc8fc\uae30 \uc815\ubcf4 XML \ucf54\ub4dc\ub294 ID\uac00 plant_watering_header \ubc0f plant_watering\uc778 \ub450 \uac1c\uc758 TextView\ub85c \uad6c\uc131\ub41c\ub2e4. \uc774\uc804\uc5d0 \ud588\ub358 \uc791\uc5c5\uacfc \uc720\uc0ac\ud558\uac8c PlantWatering\uc774\ub77c\ub294 \uc0c8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[38],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/45782"}],"collection":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=45782"}],"version-history":[{"count":1,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/45782\/revisions"}],"predecessor-version":[{"id":45783,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/45782\/revisions\/45783"}],"wp:attachment":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=45782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=45782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=45782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}