[Android] Compose

์ •์ƒ์ค€ยท2023๋…„ 6์›” 12์ผ
0
post-custom-banner

๐Ÿ“ Composable ํ•จ์ˆ˜

  • ๊ตฌ์„ฑ ๊ฐ€๋Šฅํ•œ ํ•จ์ˆ˜๋Š” ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ํ—ˆ์šฉํ•˜์—ฌ ์•ฑ ๋กœ์ง์ด UI๋ฅผ ์„ค๋ช…ํ•˜๊ฑฐ๋‚˜ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค๋‹ˆ๋‹ค.
  • ํ•จ์ˆ˜๋Š” ์•„๋ฌด๊ฒƒ๋„ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  • ์–ด๋…ธํ…Œ์ด์…˜ @Composable์„ ๋ถ™์—ฌ์•ผ ํ•œ๋‹ค.

๐Ÿ“ Composable ํ•จ์ˆ˜ ์ด๋ฆ„ํŠน์ง•

  • ํŒŒ์Šค์นผ ํ‘œ๊ธฐ๋ฒ•์‚ฌ์šฉ
  • ๋ช…์‚ฌ์—ฌ์•ผ ํ•จ: DoneButton()
  • ๋™์‚ฌ ๋˜๋Š” ๋™์‚ฌ๊ตฌ์ด๋ฉด ์•ˆ ๋จ: DrawTextField()
  • ๋ช…์‚ฌํ™”๋œ ์ „์น˜์‚ฌ์ด๋ฉด ์•ˆ ๋จ: TextFieldWithLink()
  • ํ˜•์šฉ์‚ฌ์ด๋ฉด ์•ˆ ๋จ: Bright()
  • ๋ถ€์‚ฌ์ด๋ฉด ์•ˆ ๋จ: Outside()
  • ๋ช…์‚ฌ ์•ž์—๋Š” ๋ช…์‚ฌ๋ฅผ ์„ค๋ช…ํ•˜๋Š” ํ˜•์šฉ์‚ฌ๋ฅผ ๋ถ™์ผ ์ˆ˜๋„ ์žˆ์Œ: RoundIcon()

๐Ÿ“ Compose ๋ ˆ์ด์•„์›ƒ

Compose๋Š” ํ–‰, ์—ด, ๋ฐ•์Šค ์„ธ๊ฐ€์ง€ ๊ธฐ๋ณธ ๋ ˆ์ด์•„์›ƒ์„ ๊ฐ€์ง„๋‹ค.

//row ex)
Row {
        Text(
            text = from,
            fontSize = 24.sp
        )
        Text(
            text = message,
            fontSize = 36.sp
        )
    }

๐Ÿ“ Compose image ์ถ”๊ฐ€

image composable์‚ฌ์šฉ
painter : ์ด๋ฏธ์ง€ ๋ฆฌ์†Œ์Šค ID
contentDescription : ๊ตฌ๊ธ€์€ ์žฅ์• ๊ฐ€ ์žˆ๋Š” ์‚ฌ์šฉ์ž์—๊ฒŒ TalkBack์ด๋ผ๋Š” ์„œ๋น„์Šค๋ฅผ ํ†ตํ•ด ํ™”๋ฉด์„ ์ฝ์–ด์ฃผ๋Š”๋ฐ ๊ทธ๋•Œ ์ฝํž ๋ฌธ์ž์—ด์„ ์ž…๋ ฅ. nullSafety์ด๊ธฐ ๋•Œ๋ฌธ์— null์ž…๋ ฅํ•˜๋ฉด talkBackํ•  ๋•Œ ์ƒ๋žตํ•จ

@Composable
fun BirthdayGreetingWithImage(message: String, from: String) {
    val image = painterResource(id = R.drawable.androidparty)

    Image(
        painter = image,
        contentDescription = null
    )
}
profile
์•ˆ๋“œ๋กœ์ด๋“œ๊ฐœ๋ฐœ์ž
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€