MainActivity.kt
package com.cfsuman.jetpackcompose
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Card
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.text.font.FontFamily
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MainContent()
}
}
@Composable
fun MainContent(){
val list = (0..100).map { it.toString() }
LazyColumn(
modifier = Modifier
.fillMaxSize()
.background(Color(0xFFF0F8FF))
) {
items(items = list, itemContent = { item ->
Card(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight(Alignment.CenterVertically)
.padding(
top = 4.dp,
end = 8.dp,
bottom = 4.dp,
start = 8.dp
),
backgroundColor = Color(0xFFFEFEFA),
elevation = 8.dp
) {
Text(
text = item,
fontSize = 50.sp,
fontFamily = FontFamily.Cursive,
modifier = Modifier.padding(25.dp),
textAlign = TextAlign.Center
)
}
})
}
}
@Preview
@Composable
fun ComposablePreview(){
//MainContent()
}
}
- jetpack compose - Image from assets folder
- jetpack compose - How to use LazyRow
- jetpack compose - Animate color change
- jetpack compose - Animate visibility change
- jetpack compose - String resource plurals
- jetpack compose - Get dimension resource
- jetpack compose - Get color resource
- jetpack compose - LazyColumn content spacing padding
- jetpack compose - LazyRow content padding spacing
- jetpack compose - LazyVerticalGrid
- jetpack compose - LazyColumn scroll to position
- jetpack compose - LazyColumn alternate item color
- jetpack compose - LazyColumn sticky header
- jetpack compose - SlideIn SlideOut animation
- jetpack compose - Infinite repeatable animation