기본 콘텐츠로 건너뛰기

안드로이드 앱 만들기 : Jetpack Compose 와 xml 의 차이


원본출처: 티스토리 바로가기

https://medium.com/kotlin-academy/say-hello-to-jetpack-compose-and-compare-with-xml-6bc6053aec13

 

Say Hello 👋 to Jetpack Compose and Compare with XML

Introduction

blog.kotlin-academy.com

오늘도 또 하나의 글을 찾았다... Jetpack Compose 로 만드는 화면과 기존 xml 로 만드는 화면의 차이에 대한 글을 하나 찾았다.

 

xml 와 만드는 화면과 Jetpack Compose 을 비교해 보니 이해가 되는 것 같기도 하고... 아직은 갈 길이 멀어 보인다.

 

<xml layout 예제>

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent">      <LinearLayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:gravity="center"         android:orientation="vertical">          <TextView             android:id="@+id/txtHeader"             style="@style/TextAppearance.MaterialComponents.Headline2"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_marginBottom="20dp"             android:paddingHorizontal="20dp"             android:text="Hello Compose"             android:textAlignment="center" />          <ImageView             android:id="@+id/imgSelectedAnimal"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:contentDescription="selected animal image"             android:paddingHorizontal="20dp"             android:scaleType="centerCrop"             android:layout_marginBottom="20dp"             android:src="@drawable/ic_launcher_foreground" />          <LinearLayout             android:layout_width="match_parent"             android:layout_marginBottom="20dp"             android:layout_height="wrap_content"             android:gravity="center"             android:orientation="horizontal">              <RadioButton                 android:id="@+id/radioButtonDog"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content" />              <Space                 android:layout_width="100dp"                 android:layout_height="wrap_content" />              <RadioButton                 android:id="@+id/radioButtonCat"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content" />          </LinearLayout>          <Button             android:id="@+id/btnScrollToTop"             android:layout_width="wrap_content"             android:backgroundTint="@color/black"             android:textColor="@color/white"             android:text="Scroll to Top"             android:textAllCaps="false"             android:layout_height="wrap_content"/>      </LinearLayout>  </ScrollView>

 

<Jetpack Compose 화면 예제>

        val scrollState = rememberScrollState()         val scope = rememberCoroutineScope()         var selectedAnimal by remember { mutableStateOf<Animal?>(null) }          Column(             modifier = Modifier                 .fillMaxSize()                 .verticalScroll(scrollState),             verticalArrangement = Arrangement.spacedBy(20.dp),             horizontalAlignment = Alignment.CenterHorizontally         ) {             Text(                 text = "Hello Compose",                 style = MaterialTheme.typography.h2,                 textAlign = TextAlign.Center,                 modifier = Modifier                     .fillMaxWidth()                     .padding(horizontal = 24.dp)             )              Image(                 painter = painterResource(                     id = selectedAnimal?.imageSrc ?: R.drawable.ic_launcher_foreground                 ),                 contentDescription = "selected animal image",                 modifier = Modifier                     .fillMaxWidth(fraction = 0.75f)                     .aspectRatio(3 / 8f),                 contentScale = ContentScale.Crop             )              Row(                 modifier = Modifier                     .fillMaxWidth()                     .wrapContentHeight(),                 horizontalArrangement = Arrangement.SpaceEvenly             ) {                  RadioButton(                     selected = selectedAnimal is Animal.Dog,                     onClick = { selectedAnimal = Animal.Dog },                 )                  RadioButton(                     selected = selectedAnimal is Animal.Cat,                     onClick = { selectedAnimal = Animal.Cat },                 )             }              Button(                 onClick = {                     scope.launch {                         scrollState.animateScrollTo(0)                     }                 },                 colors = ButtonDefaults.buttonColors(                     backgroundColor = Color.Black,                     contentColor = Color.White,                 )             ) {                 Text(text = "Scroll to Top")             }              Spacer(modifier = Modifier.size(100.dp))         }

 

이렇게 구현하는 것을 언제 쯤 이면 수월하게 할 수 있을 까 ?  잘 되는 날이 올 때 까지...

 

다시한번 글을 작성해 주신 원작자에게 감사를 드리며... 잘 읽어 보겠습니다.

귤탐 당도선별 감귤 로열과, 3kg(S~M), 1박스 삼립 호빵 발효미종 단팥, 92g, 14개입 [엉클컴퍼니] 우리밀 찐빵/흑미찐빵/단호박찐빵/고구마찐빵 국산팥, 우리밀 고구마찐빵(20개입) 1300g 국산팥 우리밀 MORIT 여성용 방한장갑 터치스크린 다용도 고급겨울장갑 에이치머스 스마트폰 터치 방한 장갑
이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.

댓글

이 블로그의 인기 게시물

이번주 로또 당첨 번호을 알려 드립니다.

Good Lock !!! 참조 site 티스토리 ## 로또 번호 예측 분석 및 5개 조합 제안 (자세한 설명 포함) 제공하신 1147회차부터 1167회차까지의 로또 당첨 번호 데이터를 분석하여 다음 회차(1168회차)의 예상 번호 조합 5개를 제시합니다. 분석은 제시된 6가지 통계적 패턴을 기반으로 이루어지며, 각 패턴의 주기성과 이전 회차와의 비교를 통해 예측합니다. 마지막 10회차 당첨 번호와 중복되지 않는 조합을 우선적으로 제시합니다. **1. 분석 방법:** 각 회차의 당첨 번호 6개 (7개 중 마지막 숫자 제외)를 사용하여 다음과 같은 통계 분석을 수행합니다. * **연속 번호 간격:** 연속된 번호가 나타날 때 그 사이의 간격을 계산합니다. (예: 1, 2, 4의 경우 간격은 1, 2입니다.) * **홀짝 개수 및 간격:** 홀수와 짝수의 개수를 세고, 홀수와 짝수가 번갈아 나오는 간격을 계산합니다. * **총합 및 총합 간격:** 각 회차의 번호 총합을 계산하고, 같은 총합이 이전에 나타났던 회차까지의 간격을 구합니다. * **평균 및 평균 간격:** 각 회차의 번호 평균을 계산하고, 같은 평균이 이전에 나타났던 회차까지의 간격을 구합니다. * **일치율 및 일치율 간격:** 위 1~4번의 결과들을 종합하여 일치율을 계산하고, 같은 일치율이 이전에 나타났던 회차까지의 간격을 구합니다. (일치율 계산은 각 지표의 비율을 종합적으로 고려하는 방식으로, 단순한 수치 합산이 아닌, 전문적인 통계 기법이 필요할 수 있습니다. 이 예시에서는 간략화된 추세 분석 방식을 사용합니다.) **2. 데이터 분석 및 패턴 발견 (간략화):** 제공된 데이터의 양이 많지 않고, 복잡한 통계 기법을 적용하기에는 제한적이므로, 간략화된 추세 분석을 통해 주요 패턴을 파악합니다. 실제 분석에서는 더욱 정교한 통계 기법 (예: 시계열 분석, 마르코프 체인 등)을 적용해야 더 정확한 예측이 가능합니다. **3. 예상 번호 조합 제...

이번주 로또 당첨 번호을 알려 드립니다.

Good Lock !!! 참조 site 티스토리 ## 로또 분석 및 예상 번호 추천 (1167회차) 제공해주신 1146회부터 1166회차까지의 로또 당첨번호 데이터를 분석하여 1167회차 예상 번호를 제시합니다. 아래 분석은 제공된 데이터에 기반하며, 로또는 순전히 확률에 의존하는 게임이므로 예측의 정확성을 보장할 수 없습니다. **1. 분석 방법:** 제공하신 데이터를 바탕으로 다음과 같은 통계적 분석을 실시했습니다. * **연속 번호 간격:** 각 회차의 당첨 번호 6개 중 연속된 숫자의 개수와 간격을 계산했습니다. 예를 들어 {1, 3, 5, 6, 8, 10} 이라면 연속된 숫자는 {5, 6}이며 간격은 1입니다. 여러 구간이 존재할 경우 각 구간의 간격을 모두 계산합니다. * **홀짝 개수 및 간격:** 각 회차의 홀수와 짝수의 개수를 계산하고, 이들의 비율 변화를 분석했습니다. * **총합 및 평균:** 각 회차의 당첨 번호 총합과 평균을 계산하고, 동일한 총합 또는 평균이 나타난 회차 간의 간격을 분석했습니다. * **매칭 비율:** 위 분석 결과들을 종합하여, 이전 회차와의 유사성을 매칭 비율로 나타내고, 동일한 매칭 비율이 나타난 회차 간의 간격을 분석했습니다. * **패턴 분석:** 위 분석 결과들을 통해 나타나는 패턴들을 분석하고, 주기성을 파악하여 다음 회차에 나타날 가능성이 높은 패턴을 예측했습니다. **2. 분석 결과 및 예상 번호:** (실제 데이터 분석을 수행해야 하므로, 아래는 예시 결과입니다. 실제 분석 결과는 위에 언급된 방법으로 계산해야 합니다.) 위 분석 결과를 바탕으로 다음과 같은 예상 번호 5가지를 제시합니다. 각 조합은 분석 결과의 패턴 및 이전 회차와의 차별성을 고려하여 선정되었습니다. 마지막 10회차 당첨 번호와 중복되지 않도록 주의했습니다. * **예상 번호 1:** 03, 12, 25, 31, 38, 42 * **예상 번호 2:** 07, 15, 21, 29, 36, 45 *...