๋ชฉ์ฐจ
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.birthdaycard.ui.theme.BirthdayCardTheme
import kotlinx.coroutines.NonCancellable
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
BirthdayCardTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colors.background
) {
BirthdayGreetingWithImage(stringResource(R.string.happy_birthday_text) , stringResource(
R.string.singature_text))
}
}
}
}
}
@Composable
fun BirthdayGreetingWithText(message: String, from: String) {
Column (horizontalAlignment = Alignment.CenterHorizontally){
Text(
text = message,
fontSize = 36.sp,
modifier = Modifier
.fillMaxWidth() // ์ปดํฌ์ ๋ธ์ ๋๋น๊ฐ ์ฌ์ฉ๊ฐ๋ฅํ ์ต๋ ๋๋น๋ก ์ค์ ๋๋ค.
.wrapContentWidth(Alignment.Start)
.padding(start = 16.dp,end=16.dp)
// wrapContentWidth : ์ฌ์ฉ๊ฐ๋ฅํ ํ๋ฉด ๋๋น(๋๋ ์์ ๋๋น)์ ๋ง์ถฐ ์ปดํฌ์ ๋ธ์ด ๋ํ๋๊ณ ์ ๋ ฌ๋๋ค.
// Alignment.Start : ํ
์คํธ ์ปดํฌ์ ๋ธ ๋๋ ํ์ ์์๊ฐ ํ๋ฉด์ ์์ ๋ถ๋ถ ๋๋ ์์ ์์์ ๋ง์ถฐ ์ ๋ ฌ๋๋ค.
)
Text(
text = from,
fontSize = 24.sp,
)
}
}
@Composable
fun BirthdayGreetingWithImage(message: String, from: String) {
val image = painterResource(R.drawable.androidparty)
Box {
Image(painter = image,
contentDescription = null,
modifier = Modifier
.fillMaxHeight()
.fillMaxWidth(),
contentScale = ContentScale.Crop
)
BirthdayGreetingWithText(message=message,from=from)
}
}
@Preview(showBackground = true)
@Composable
fun BirthdayCardTPreview() {
BirthdayCardTheme {
BirthdayGreetingWithImage(message = "Happy Birthday hyeon!","- from zu")
}
}
728x90
'2023 ์๋๋ก์ด๋ > ์๋๋ก์ด๋ ์คํฐ๋' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
unit2- ๋ํํ Dice Roller ์ฑ ๋ง๋ค๊ธฐ (0) | 2022.12.29 |
---|---|
taskmanager (0) | 2022.12.26 |
unit1- Android์ฑ์ ์ด๋ฏธ์ง ์ถ๊ฐ (0) | 2022.12.24 |
Unit1- Jetpack Compose๋ ๋ฌด์์ธ๊ฐ์? (0) | 2022.12.24 |
4.Compose ์ฌ๋ถ๋ฉด (0) | 2022.11.17 |