/* 2023-01-18 File created by Kari Laitinen. (c) naturalprogramming.com This simple app demonstrates how we can show a set of items in a scrollable column. https://developer.android.com/jetpack/compose/lists Similar app made with older Android classes is called RecyclerViewDemo. */ package lazycolumn.demo import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn 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.platform.LocalConfiguration import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import lazycolumn.demo.ui.theme.LazyColumnDemoTheme @Composable fun ComputingGuy( given_name : String ) { Box( contentAlignment = Alignment.Center, modifier = Modifier.fillMaxWidth() .requiredHeight( 140.dp ) .background( Color( 0xFFFF9800.toInt() ) ) ) { Text( given_name, fontSize = 28.sp ) } } class LazyColumnDemoActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { LazyColumnDemoTheme { // A surface container using the 'background' color from the theme Surface( modifier = Modifier.fillMaxSize(), color = MaterialTheme.colors.background) { //val configuration = LocalConfiguration.current //val screen_height = configuration.screenHeightDp.dp //val screen_width = configuration.screenWidthDp.dp val computing_guys : Array = arrayOf( "Steve Jobs", "Steve Wozniak", "Alan Turing", "Ada Lovelace", "Linus Torvalds", "Bill Gates", "Douglas Engelbart", "John von Neumann", "Gary Kildall", "Tim Paterson", "Tim Berners-Lee" ) LazyColumn( // The following will put some space between // the items in the column. verticalArrangement = Arrangement.spacedBy( 8.dp ) ) { // Add a single item item { ComputingGuy( "Charles Babbage" ) } // Add all from the array. items( computing_guys.size ) { index -> ComputingGuy( computing_guys[ index ] ) } // Add another single item item { ComputingGuy( "ChatGPT" ) } } } } } } }