Jetpack compose ui: Как создать Cardview? - PullRequest
3 голосов
/ 17 октября 2019

Я хочу создать Cardview с помощью Jetpack Comose, но я не могу найти ни одного примера.

enter image description here

Заранее спасибо.

Ответы [ 2 ]

6 голосов
/ 17 октября 2019

Вот пример просмотра карты Использование Jetpack Compose

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            demoApp()
        }
    }

    @Composable
    fun demoApp() {
        MaterialTheme {
            Container {
                cardDemo()
            }
        }
    }

    @Composable
    private fun cardDemo() {
        val shape = RoundedCornerShape(10.dp)
        Card(shape = shape, elevation = 10.dp) {
            Padding(padding = 10.dp) {
                Container {
                    Text("Card View Demo", style = TextStyle(color = Color.Black))
                }
            }
        }
    }
}

enter image description here

0 голосов
/ 26 октября 2019

Вы можете использовать что-то вроде:

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContent {
        MaterialTheme {

            Column(
                modifier = Spacing(32.dp),
                crossAxisSize = LayoutSize.Expand
            ) {
                //Card with 8dp rounded corners
                Card(shape = RoundedCornerShape(8.dp)) {
                    //Padding inside the card
                    Padding(padding = 16.dp) {
                        // Main container inside the card with height= 200dp
                        Container(height = 200.dp, expanded = true) {
                            //Text element with custom style
                            Text("This is a card view",
                                style = +themeTextStyle { h4 })
                        }
                    }
                }
            }

        }
    }
}

enter image description here

...