๋ชฉ์ฐจ
์ด๊ฒ์ ๊ตฌํํด์ผํ๋ค.
์ด๋ ค์
ใ ใ ใ ใ ใ ๊ทผ๋ฐ
modifier = Modifier
.weight(1f,false).background(Color.Green)
.padding(top = 16.dp, end = 16.dp, bottom = 16.dp, start = 16.dp)
.fillMaxWidth(
์ฌ๊ธฐ์ weight ์ค๋ฅ๊ฐ ๋ฌ๋ค. import๋ฅผ ํด๋ ์ ๋นจ๊ฐ ์ ์ด ์์์ด์ง์ง........
์๋ฃจ์ ์ฝ๋
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.composequadrant
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
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.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.composequadrant.ui.theme.ComposeQuadrantTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ComposeQuadrantTheme {
// A surface container using the 'background' color from the theme
Surface(color = MaterialTheme.colors.background) {
ComposeQuadrantApp()
}
}
}
}
}
@Composable
fun ComposeQuadrantApp() {
Column(Modifier.fillMaxWidth()) {
Row(Modifier.weight(1f)) {
ComposableInfoCard(
title = stringResource(R.string.first_title),
description = stringResource(R.string.first_description),
backgroundColor = Color.Green,
modifier = Modifier.weight(1f)
)
ComposableInfoCard(
title = stringResource(R.string.second_title),
description = stringResource(R.string.second_description),
backgroundColor = Color.Yellow,
modifier = Modifier.weight(1f)
)
}
Row(Modifier.weight(1f)) {
ComposableInfoCard(
title = stringResource(R.string.third_title),
description = stringResource(R.string.third_description),
backgroundColor = Color.Cyan,
modifier = Modifier.weight(1f)
)
ComposableInfoCard(
title = stringResource(R.string.fourth_title),
description = stringResource(R.string.fourth_description),
backgroundColor = Color.LightGray,
modifier = Modifier.weight(1f)
)
}
}
}
@Composable
private fun ComposableInfoCard(
title: String,
description: String,
backgroundColor: Color,
modifier: Modifier = Modifier
) {
Column(
modifier = modifier
.fillMaxSize()
.background(backgroundColor)
.padding(16.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text(
text = title,
fontWeight = FontWeight.Bold,
modifier = Modifier.padding(bottom = 16.dp)
)
Text(
text = description,
textAlign = TextAlign.Justify
)
}
}
@Preview(showBackground = true)
@Composable
fun ComposeQuadrantAppPreview() {
ComposeQuadrantTheme {
ComposeQuadrantApp()
}
}
Footer
© 2022 GitHub, Inc.
Footer navigation
Terms
P
Column Row Box๋ก ๊ฐ์ธ๋๊ฒ ์ดํด๊ฐ ์๊ฐ๋ค
์ ์ฒด์ ์ผ๋ก Column์ผ๋ก ํ๋ฒ๋ง ๊ฐ์ธ๋ฉด ๊ทธ ์์ ์์๋ ๋ค ์ด๋ฐฉํฅ์ผ๋ก ์ ๋ ฌ๋๋ ๊ฒ์ธ๊ฐ.?
์ผ๋จ 2๋ฒ์ด๋ 3๋ฒ ํด๊ฒฐ๋ชปํ๋ค.
-> ๋ค์ ํ ๊ฒ!
๋ธ๋ก๊ทธ ๋ด์ฉ ๋ฐ๋ผํ๊ธฐ Modifier
# fill~ ์ ๋ฆฌ
Modifier.fillMaxWidth( ) : ๋๋น(๊ฐ๋ก) ์ ์ฒด ์ฑ์ฐ๊ธฐ
Modifier.fillMaxHeight() : ๋์ด(์ธ๋ก) ์ ์ฒด ์ฑ์ฐ๊ธฐ
Modifier.fillMaxSize( ) : ๋๋น , ๋์ด ๋ชจ๋ ์ ์ฒด ์ฑ์ฐ๊ธฐ, ๊ธฐ๋ณธ์ ๋ชจ๋ ์ฑ์ฐ๋ ๊ฒ
728x90
'2023 ์๋๋ก์ด๋ > ์๋๋ก์ด๋ ์คํฐ๋' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
unit1- Android์ฑ์ ์ด๋ฏธ์ง ์ถ๊ฐ (0) | 2022.12.24 |
---|---|
Unit1- Jetpack Compose๋ ๋ฌด์์ธ๊ฐ์? (0) | 2022.12.24 |
์ฐ์ต: Compose ๊ธฐ๋ณธ ์ฌํญ (0) | 2022.11.17 |
10. ์๋ฃจ์ ์ฝ๋ ๊ฐ์ ธ์ค๊ธฐ ~ 11. ๊ฒฐ๋ก (0) | 2022.11.16 |
Android ์ฑ์ ์ด๋ฏธ์ง ์ถ๊ฐ [ ๋์ ๊ณผ์ ] (0) | 2022.11.16 |