《Jetpack Compose从入门到实战》 第二章 了解常用UI组件

news2024/11/25 0:48:35

目录

  • 常用的基础组件
    • 文字组件
    • 图片组件
    • 按钮组件
    • 选择器组件
    • 对话框组件
    • 进度条组件
  • 常用的布局组件
    • 布局
    • Scaffold脚手架
  • 列表

在这里插入图片描述
书附代码
Google的图标库

常用的基础组件

文字组件


@Composable
fun TestText() {
    Column(modifier = Modifier.verticalScroll(state = rememberScrollState())) {
        Text(text = "hello world")
        Text(text = "hello world")
        Text(text = "hello world")
        Text(text = stringResource(id = R.string.hello_world))
        Text(
            text = stringResource(id = R.string.hello_world),
            style = TextStyle(
                fontSize = 25.sp,//字体大小
                fontWeight = FontWeight.Bold,//字体粗细
                fontStyle = FontStyle.Italic,//斜体,
                background = Color.Cyan,
                lineHeight = 35.sp,//行高
            ),
        )
        Text(
            text = stringResource(id = R.string.hello_world),
            style = TextStyle(color = Color.Gray, letterSpacing = 4.sp)
        )
        Text(
            text = stringResource(id = R.string.hello_world),
            style = TextStyle(textDecoration = TextDecoration.LineThrough)
        )

        Text(
            text = stringResource(id = R.string.hello_world),
            style = MaterialTheme.typography.h6.copy(fontStyle = FontStyle.Italic)
        )

        Text(
            text = "Hello Compose, Compose是下一代Android UI工具包, 开发起来和以往XML写布局有着非常大的不同",
            style = MaterialTheme.typography.body1
        )
        Text(
            text = "Hello Compose, Compose是下一代Android UI工具包, 开发起来和以往XML写布局有着非常大的不同",
            style = MaterialTheme.typography.body1,
            maxLines = 1
        )
        Text(
            text = "Hello Compose, Compose是下一代Android UI工具包, 开发起来和以往XML写布局有着非常大的不同",
            style = MaterialTheme.typography.body1,
            maxLines = 1,
            overflow = TextOverflow.Ellipsis,
        )

        Text(text = stringResource(id = R.string.hello_world), fontFamily = FontFamily.Cursive)
        Text(text = stringResource(id = R.string.hello_world), fontFamily = FontFamily.Monospace)
        Text(
            text = "你好,我的世界", fontFamily = FontFamily(Font(R.font.test_font))
        )

        Text(text = buildAnnotatedString {
            appendLine("-------------------------------")
            withStyle(style = SpanStyle(fontSize = 24.sp)) {
                append("你现在学的章节是")
            }
            withStyle(style = SpanStyle(fontWeight = FontWeight.W900, fontSize = 24.sp)) {
                append("Text")
            }
            appendLine()
            withStyle(style = ParagraphStyle(lineHeight = 25.sp)) {
                append("在刚刚讲过的内容中, 我们学会了如何应用文字样式, 以及如何限制文本的行数和处理溢出的视觉效果")
            }
            appendLine()
            append("现在,我们正在学习")
            withStyle(
                style = SpanStyle(
                    fontWeight = FontWeight.W900,
                    textDecoration = TextDecoration.Underline,
                    color = Color(0xFF59A869)
                )
            ) {
                append("AnnotatedString")
            }

        })
        val annotatedString = buildAnnotatedString {
            withStyle(style = ParagraphStyle()) {
                append("点击下面的链接查看更多")
                pushStringAnnotation(
                    tag = "URL", annotation = "https://jetpackcompose.cn/docs/elements/text"
                )
                withStyle(
                    style = SpanStyle(
                        fontWeight = FontWeight.W900,
                        textDecoration = TextDecoration.Underline,
                        color = Color(0xFF59A869)
                    )
                ) {
                    append("参考链接")
                }
                pop()//结束之前添加的样式
                appendLine("-------------------------------")
            }
        }

        val currentContext = LocalContext.current
        ClickableText(text = annotatedString, onClick = { offset ->
            annotatedString.getStringAnnotations(tag = "URL", start = offset, end = offset)
                .firstOrNull()?.let { annotation ->
                    val uri: Uri = Uri.parse(annotation.item)
                    val intent = Intent(Intent.ACTION_VIEW, uri)
                    startActivity(currentContext, intent, null)
                }
        })

        SelectionContainer {
            Text(text = "可以被选中复制的文字")
        }
        TestTextField()
    }
}

@Composable
fun TestTextField() {
    var textFields by remember { mutableStateOf("") }
    TextField(value = textFields,
        onValueChange = { textFields = it },
        label = { Text(text = "user name") })

    var userName by remember {
        mutableStateOf("")
    }

    var password by remember {
        mutableStateOf("")
    }

    TextField(value = userName,
        onValueChange = { userName = it },
        label = { Text(text = "用户名") },
        leadingIcon = {
            Icon(
                imageVector = Icons.Filled.AccountBox, contentDescription = "username"
            )
        })

    TextField(value = password,
        onValueChange = { password = it },
        label = { Text(text = "密码") },
        trailingIcon = {
            IconButton(onClick = {}) {
                Icon(
                    painter = painterResource(id = R.drawable.visibility),
                    contentDescription = "password"
                )
            }
        })
    var outlinedTextFields by remember { mutableStateOf("Hello World") }
    OutlinedTextField(value = outlinedTextFields, onValueChange = { outlinedTextFields = it })

    //不是basicTextField,属性被material theme所限制,例如修改高度,输入区域会被截断,影响显示效果
    TextField(value = userName,
        onValueChange = { userName = it },
        label = { Text(text = "用户名") },
        leadingIcon = {
            Icon(
                imageVector = Icons.Filled.AccountCircle, contentDescription = null
            )
        },
        modifier = Modifier.height(30.dp)
    )


    var basicTextFields by remember { mutableStateOf("") }

    BasicTextField(
        value = basicTextFields,
        onValueChange = { basicTextFields = it },
        decorationBox = { innerTextField ->
            Column {
                innerTextField.invoke()//innerTextField代表输入框开始输入的位置,需要在合适的地方调用
                Divider(
                    thickness = 1.dp, modifier = Modifier
                        .fillMaxWidth()
                        .background(Color.Black)
                )
            }
        },
        modifier = Modifier
            .height(40.dp)
            .background(Color.Cyan),
    )
    Spacer(modifier = Modifier.height(15.dp))
    SearchBar()
    Spacer(modifier = Modifier.height(15.dp))

}

@Composable
fun SearchBar() {
    var searchText by remember { mutableStateOf("") }
    Box(
        modifier = Modifier
            .fillMaxWidth()
            .height(50.dp)
            .background(Color(0xFFD3D3D3)),
        contentAlignment = Alignment.Center
    ) {
        BasicTextField(
            value = searchText,
            onValueChange = { searchText = it },
            decorationBox = { innerTextField ->
                Row(
                    verticalAlignment = Alignment.CenterVertically,
                    modifier = Modifier.padding(vertical = 2.dp, horizontal = 8.dp)
                ) {
                    Icon(imageVector = Icons.Filled.Search, contentDescription = "")
                    Box(
                        modifier = Modifier
                            .padding(horizontal = 10.dp)
                            .weight(1f),
                        contentAlignment = Alignment.CenterStart
                    ) {
                        if (searchText.isEmpty()) {
                            Text(text = "搜索", style = TextStyle(color = Color(0, 0, 0, 128)))
                        }
                        innerTextField()
                    }
                    if (searchText.isNotEmpty()) {
                        IconButton(
                            onClick = { searchText = "" }, modifier = Modifier.size(16.dp)
                        ) {
                            Icon(imageVector = Icons.Filled.Clear, contentDescription = "")
                        }
                    }
                }
            },
            modifier = Modifier
                .padding(horizontal = 10.dp)
                .height(30.dp)
                .fillMaxWidth()
                .background(Color.White, CircleShape),
        )
    }
}

在这里插入图片描述

图片组件

@Composable
fun TestImage() {
    Column {

        //Material Icon默认的tint颜色会是黑色, 所以彩色的icon,也会变成黑色
        Icon(
            imageVector = ImageVector.vectorResource(id = R.drawable.collect),//xml svg矢量图
            contentDescription = "矢量图资源"
        )
        //将tint设置为Color.Unspecified, 即可显示出多色图标
        Icon(
            imageVector = ImageVector.vectorResource(id = R.drawable.collect),//xml svg矢量图
            contentDescription = "矢量图资源", tint = Color.Unspecified
        )

        Icon(
            bitmap = ImageBitmap.imageResource(id = R.drawable.gallery), contentDescription = "图片资源"//加载jpg或png
        )

        Icon(painter = painterResource(id = R.drawable.visibility), contentDescription = "任意类型的资源")//任意类型的资源文件

        Image(
            imageVector = ImageVector.vectorResource(id = R.drawable.collect),//xml svg矢量图
            contentDescription = "矢量图资源"
        )

        Image(
            bitmap = ImageBitmap.imageResource(id = R.drawable.gallery), contentDescription = "图片资源"//加载jpg或png
        )

        Image(painter = painterResource(id = R.drawable.visibility), contentDescription = "任意类型的资源")//任意类型的资源文件

    }
}

按钮组件

@Composable
fun TestButton() {
    Column {
        Button(onClick = {}, contentPadding = PaddingValues(2.dp)) {
            Text(text = "确认")
        }

        Button(
            onClick = {},
            contentPadding = PaddingValues(5.dp),
            colors = ButtonDefaults.buttonColors(
                backgroundColor = Color.Cyan, contentColor = Color.Gray
            )
        ) {
            Icon(
                imageVector = Icons.Filled.Done,
                contentDescription = "",
                modifier = Modifier.size(ButtonDefaults.IconSize)
            )
            Spacer(modifier = Modifier.width(ButtonDefaults.IconSpacing))
            Text(text = "确认")
        }

        val interactionSource = remember {
            MutableInteractionSource()
        }
        val isPressedAsState = interactionSource.collectIsPressedAsState()
        val borderColor = if (isPressedAsState.value) Color.Green else Color.Cyan

        Button(
            onClick = {},
            contentPadding = PaddingValues(horizontal = 12.dp),
            border = BorderStroke(2.dp, borderColor),
            interactionSource = interactionSource
        ) {
            Text(text = "long press")
        }

        IconButton(onClick = {}) {
            Icon(
                painter = painterResource(id = R.drawable.collect_24_x_24),
                contentDescription = "",
                tint = Color.Unspecified
            )
        }

        FloatingActionButton(onClick = {}) {
            Icon(
                Icons.Filled.KeyboardArrowUp, contentDescription = ""
            )
        }

        ExtendedFloatingActionButton(icon = {
            Icon(
                Icons.Filled.Favorite, contentDescription = "", tint = Color.Unspecified
            )
        }, text = { Text(text = "add to my favorite") }, onClick = {})

    }
}

选择器组件

@Composable
fun TestSelector() {
    Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
        val checkedState = remember {
            mutableStateOf(true)
        }
        Checkbox(
            checked = checkedState.value,
            onCheckedChange = { checkedState.value = it },
            colors = CheckboxDefaults.colors(checkedColor = Color(0xFF0079D3))
        )

        val (state, onStateChange) = remember {
            mutableStateOf(true)
        }
        val (state2, onStateChange2) = remember {
            mutableStateOf(true)
        }
        val parentState = remember(state, state2) {
            if (state && state2) ToggleableState.On
            else if (!state && !state2) ToggleableState.Off
            else ToggleableState.Indeterminate
        }
        val onParentClick = {
            val s = parentState != ToggleableState.On
            onStateChange(s)
            onStateChange2(s)
        }
        TriStateCheckbox(
            state = parentState,
            onClick = onParentClick,
            colors = CheckboxDefaults.colors(checkedColor = MaterialTheme.colors.primary)
        )
        Row(modifier = Modifier.padding(10.dp, 0.dp, 0.dp, 10.dp)) {
            Checkbox(checked = state, onCheckedChange = onStateChange)
            Checkbox(checked = state2, onCheckedChange = onStateChange2)

        }

        val switchCheckedState = remember {
            mutableStateOf(true)
        }
        Switch(
            checked = switchCheckedState.value,
            onCheckedChange = { switchCheckedState.value = it },
            colors = SwitchDefaults.colors(
                checkedThumbColor = Color.Cyan, checkedTrackColor = Color.Gray
            )
        )

        var sliderPosition by remember {
            mutableStateOf(0f)
        }
        Text(
            text = "%.1f".format(sliderPosition * 100) + "%",
            modifier = Modifier.align(alignment = CenterHorizontally)
        )
        Slider(value = sliderPosition, onValueChange = { sliderPosition = it })

    }

}

对话框组件

@Composable
fun TestDialog() {
    Column {
        val openDialog = remember {
            mutableStateOf(false)
        }

        Button(onClick = {
            openDialog.value = !openDialog.value
        }) {
            Text(
                text = if (openDialog.value) "CloseDialog" else {
                    "OpenDialog"
                }
            )
        }

        if (openDialog.value) {
            Dialog(
                onDismissRequest = { openDialog.value = false }, properties = DialogProperties(
                    dismissOnBackPress = true, dismissOnClickOutside = true
                )
            ) {
                Box(
                    modifier = Modifier
                        .size(300.dp, 400.dp)
                        .background(Color.White)
                ) {
                    Button(onClick = {
                        openDialog.value = false
                    }, modifier = Modifier.align(Alignment.Center)) {
                        Text(text = "Close")
                    }
                }
            }
        }


        val alertDialog = remember {
            mutableStateOf(false)
        }

        Button(onClick = {
            alertDialog.value = !alertDialog.value
        }) {
            Text(
                text = if (alertDialog.value) "CloseAlertDialog" else {
                    "OpenAlertDialog"
                }
            )
        }

        if (alertDialog.value) {
            AlertDialog(onDismissRequest = { alertDialog.value = false },
                title = { Text(text = "开启位置服务") },
                text = {
                    Text(text = "提供精确的位置使用,请务必打开")
                },
                confirmButton = {
                    Button(onClick = { alertDialog.value = false }) {
                        Text(text = "同意")
                    }
                },
                dismissButton = {
                    TextButton(onClick = { alertDialog.value = false }) {
                        Text(text = "取消")
                    }
                })
        }
    }
}

进度条组件

@Preview
@Composable
fun TestProgress() {
    var progress by remember {
        mutableStateOf(0.1f)
    }

    val animatedProgress by animateFloatAsState(targetValue = progress, animationSpec = ProgressIndicatorDefaults.ProgressAnimationSpec, label = "progressAnim")
    Column(
        modifier = Modifier
            .padding(10.dp)
            .border(2.dp, color = MaterialTheme.colors.primary),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Center
    ) {
        CircularProgressIndicator(
            progress = animatedProgress,
            backgroundColor = MaterialTheme.colors.primary.copy(alpha = IndicatorBackgroundOpacity),
        )
        Spacer(modifier = Modifier.height(30.dp))

        LinearProgressIndicator(progress = animatedProgress, strokeCap = StrokeCap.Round)
        Spacer(modifier = Modifier.height(30.dp))
        Row {

            OutlinedButton(onClick = {
                if (progress >= 1.0f) {
                    return@OutlinedButton
                }
                progress += 0.1f
            }) {
                Text(text = "增加进度")
            }
            Spacer(modifier = Modifier.width(30.dp))
            OutlinedButton(onClick = {
                if (progress == 0f) {
                    return@OutlinedButton
                }
                progress -= 0.1f
            }) {
                Text(text = "减少进度")
            }
        }
    }
}

常用的布局组件

ConstraintLayout约束布局需要依赖:implementation “androidx.constraintlayout:constraintlayout-compose: $constraintlayout _version”

布局

@Preview
@Composable
fun TestLayout() {

    Column(
        modifier = Modifier
            .border(2.dp, color = MaterialTheme.colors.primary)
            .verticalScroll(
                rememberScrollState()
            )
    ) {
        Surface(
            shape = RoundedCornerShape(8.dp),
            modifier = Modifier
                .padding(horizontal = 12.dp, vertical = 10.dp)
                .fillMaxWidth(),
            elevation = 10.dp
        ) {
            Column(modifier = Modifier.padding(12.dp)) {
                Text(text = "Jetpack Compose是什么", style = MaterialTheme.typography.h6)
                Spacer(modifier = Modifier.padding(vertical = 5.dp))
                Text(
                    text = "Jetpack Compose是用于构建原生Android UI的现代工具包。它采用声明式UI的设计,拥有更简单的自定义和实时的交互预览功能,由Android官方团队全新打造的UI框架。Jetpack Compose可简化并加快Android上的界面开发,使用更少的代码、强大的工具和直观的Kotlin API,快速打造生动而精彩的应用。"
                )
                Row(
                    modifier = Modifier.fillMaxWidth(),
                    horizontalArrangement = Arrangement.SpaceBetween
                ) {
                    IconButton(onClick = { /*TODO*/ }) {
                        Icon(Icons.Filled.Favorite, null)
                    }
                    IconButton(onClick = { /*TODO*/ }) {
                        Icon(Icons.Filled.Add, null)
                    }
                    IconButton(onClick = { /*TODO*/ }) {
                        Icon(Icons.Filled.Star, null)
                    }
                }

            }
        }

        Spacer(modifier = Modifier.height(40.dp))
        Text(text = "约束布局")
        Spacer(modifier = Modifier.height(40.dp))

        ConstraintLayout(
            modifier = Modifier
                .width(300.dp)
                .height(100.dp)
                .padding(10.dp)
        ) {
            val (portraitImageRef, usernameTextRef, desTextRef) = remember {
                createRefs()//createRefs最多创建16个引用
            }
            Image(painter = painterResource(id = R.drawable.img),
                contentDescription = "",
                modifier = Modifier.constrainAs(portraitImageRef) {
                    top.linkTo(parent.top)
                    start.linkTo(parent.start)
                    bottom.linkTo(parent.bottom)
                })
            Text(text = "舞蹈系学姐",
                style = MaterialTheme.typography.h6,
                modifier = Modifier.constrainAs(usernameTextRef) {
                    top.linkTo(portraitImageRef.top)
                    start.linkTo(portraitImageRef.end, 10.dp)
                })
            Text(text = "一本非常好看的漫画",
                style = MaterialTheme.typography.body1,
                modifier = Modifier.constrainAs(desTextRef) {
                    top.linkTo(usernameTextRef.bottom, 10.dp)
                    start.linkTo(usernameTextRef.start)
                })
        }

        Spacer(modifier = Modifier.height(40.dp))

        ConstraintLayout(
            modifier = Modifier
                .width(300.dp)
                .height(100.dp)
                .padding(10.dp)
        ) {
            val (usernameTextRef, passwordTextRef, usernameInputRef, passwordInputRef, dividerRef) = remember {
                createRefs()//createRefs最多创建16个引用
            }
            val barrier = createEndBarrier(usernameTextRef, passwordTextRef)

            Text(text = "用户名", modifier = Modifier.constrainAs(usernameTextRef) {
                top.linkTo(parent.top)
                start.linkTo(parent.start)
            })

            Divider(
                Modifier
                    .fillMaxWidth()
                    .constrainAs(dividerRef) {
                        top.linkTo(usernameTextRef.bottom)
                        bottom.linkTo(passwordTextRef.top)

                    })

            Text(text = "密码", modifier = Modifier.constrainAs(passwordTextRef) {
                top.linkTo(usernameTextRef.bottom, 19.dp)
                start.linkTo(parent.start)
            })
            OutlinedTextField(value = "456546461",
                onValueChange = {},
                modifier = Modifier.constrainAs(usernameInputRef) {
                    start.linkTo(barrier, 10.dp)
                    top.linkTo(usernameTextRef.top)
                    bottom.linkTo(usernameTextRef.bottom)
                    height = Dimension.fillToConstraints
                })


            OutlinedTextField(value = "4645136131",
                onValueChange = {},
                modifier = Modifier.constrainAs(passwordInputRef) {
                    start.linkTo(barrier, 10.dp)
                    top.linkTo(passwordTextRef.top)
                    bottom.linkTo(passwordTextRef.bottom)
                    height = Dimension.fillToConstraints
                })

        }

        Spacer(modifier = Modifier.height(20.dp))

        ConstraintLayout(
            modifier = Modifier
                .fillMaxWidth()
                .height(200.dp)
                .padding(10.dp)
                .background(Color.Gray)
        ) {
            val (backgroundRef, avatarRef, textRef) = remember {
                createRefs()
            }

            val guideLine = createGuidelineFromTop(0.4f)
            Box(modifier = Modifier
                .constrainAs(backgroundRef) {
                    top.linkTo(parent.top)
                    bottom.linkTo(guideLine)
                    width = Dimension.matchParent
                    height = Dimension.fillToConstraints
                }
                .background(Color(0xFF1E9FFF)))

            Image(painter = painterResource(id = R.drawable.avatar),
                contentDescription = "",
                modifier = Modifier.constrainAs(avatarRef) {
                    top.linkTo(guideLine)
                    bottom.linkTo(guideLine)
                    start.linkTo(parent.start)
                    end.linkTo(parent.end)
                })
            Text(text = "排雷数码港", color = Color.White, modifier = Modifier.constrainAs(textRef) {
                top.linkTo(avatarRef.bottom, 10.dp)
                start.linkTo(parent.start)
                end.linkTo(parent.end)
            })

        }

        Spacer(modifier = Modifier.height(20.dp))
        ConstraintLayout(
            modifier = Modifier
                .fillMaxWidth()
                .height(200.dp)
                .padding(10.dp)
                .background(Color.Gray)
        ) {
            val (text1Ref, text2Ref, text3Ref, text4Ref) = remember {
                createRefs()
            }
            /*createVerticalChain(
                text1Ref, text2Ref, text3Ref, text4Ref, chainStyle = ChainStyle.Spread
            )*/
            /*createVerticalChain(
                text1Ref, text2Ref, text3Ref, text4Ref, chainStyle = ChainStyle.Packed
            )*/
            createVerticalChain(
                text1Ref, text2Ref, text3Ref, text4Ref, chainStyle = ChainStyle.SpreadInside
            )
            Text(text = "text1", modifier = Modifier.constrainAs(text1Ref) {
                start.linkTo(parent.start)
                end.linkTo(parent.end)
            })

            Text(text = "text2", modifier = Modifier.constrainAs(text2Ref) {
                start.linkTo(parent.start)
                end.linkTo(parent.end)
            })
            Text(text = "text3", modifier = Modifier.constrainAs(text3Ref) {
                start.linkTo(parent.start)
                end.linkTo(parent.end)
            })
            Text(text = "text4", modifier = Modifier.constrainAs(text4Ref) {
                start.linkTo(parent.start)
                end.linkTo(parent.end)
            })
        }

Scaffold脚手架

data class Item(val name: String, val icon: Int)

@SuppressLint("UnusedMaterialScaffoldPaddingParameter")
@Composable
fun TestScaffold() {

    val selectedItem by remember {
        mutableStateOf(0)
    }
    val items = listOf<Item>(
        Item("主页", R.drawable.home),
        Item("列表", R.drawable.list),
        Item("设置", R.drawable.setting)
    )

    val scaffoldState = rememberScaffoldState()
    val scope = rememberCoroutineScope()

    Scaffold(topBar = {
        TopAppBar(title = { Text(text = "主页") }, navigationIcon = {
            IconButton(
                onClick = {
                    scope.launch {
                        scaffoldState.drawerState.open()
                    }
                },
            ) {
                Icon(Icons.Filled.Menu, contentDescription = "")
            }
        })
    }, bottomBar = {
        BottomNavigation {
            items.forEachIndexed { index, item ->
                BottomNavigationItem(selected = selectedItem == index, onClick = { }, icon = {
                    Icon(
                        painter = painterResource(id = item.icon), contentDescription = item.name
                    )
                }, alwaysShowLabel = false, label = { Text(text = item.name) })
            }
        }
    }, drawerContent = { Text(text = "侧边栏") }, scaffoldState = scaffoldState) {
        Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
            Text(text = "主页界面")
        }

    }
    BackHandler(enabled = scaffoldState.drawerState.isOpen) {
        scope.launch {
            scaffoldState.drawerState.close()
        }
    }
}

列表

@Preview
@Composable
fun TestList() {
    LazyColumn(
        modifier = Modifier
            .fillMaxSize()
            .background(Color.Gray),
        contentPadding = PaddingValues(35.dp),
        verticalArrangement = Arrangement.spacedBy(10.dp)
    ) {
        items((1..50).toList()) { index ->
            ContentCard(index = index)
        }
    }
}

@Composable
fun ContentCard(index: Int) {
    Card(elevation = 8.dp, modifier = Modifier.fillMaxWidth()) {
        Box(
            modifier = Modifier
                .fillMaxSize()
                .padding(15.dp), contentAlignment = Alignment.Center
        ) {
            Text(text = "第${index}卡片", style = MaterialTheme.typography.h5)
        }
    }
}

Jetpack Compose从入门到实战 第一章

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1053905.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

ESP32官方MPU6050组件介绍

前言 &#xff08;1&#xff09;因为我需要使用MPU6050的组件&#xff0c;但是又需要在这条I2C总线上挂载多个设备&#xff0c;所以我本人打算自己对官方的MPU6050的组件进行微调。建立一个I2C总线&#xff0c;设备依赖于这个总线挂载。 &#xff08;2&#xff09;既然要做移植…

list(链表)

文章目录 功能迭代器的分类sort函数&#xff08;排序&#xff09;merage&#xff08;归并&#xff09;unique(去重&#xff09;removesplice&#xff08;转移&#xff09; 功能 这里没有“[]"的实现&#xff1b;原因&#xff1a;实现较麻烦&#xff1b;这里使用迭代器来实…

vue3基础语法

2020年9月18日发布 2022年2月7日称为默认版本&#xff0c;意味vue3是现在也是未来 Ant Design Pc端组件库 Element Plus Pc端组件库 Vant 移动端 VueUse 基于composition 组合式api的常用函数集合 vue3中文文档&#xff1a;https://cn.vuejs.org/guide/introduction.html…

pandas_datareader读取yahoo金融数据超时问题timeout解决方案

在《Python金融数据挖掘》一书中&#xff0c;学习到网络数据源这一章节&#xff0c;利用书中的方法安装了pandas_datareader包&#xff0c;但在获取雅虎数据&#xff08;get_data_yahoo&#xff09;时会出现以下问题&#xff1a; 经过仔细分析和尝试&#xff0c;排除了yahoo受中…

2023年中国智能电视柜产量、需求量、市场规模及行业价格走势[图]

电视柜是随着电视机的发展和普及而演变出的家具种类&#xff0c;其主要作用是承载电视机&#xff0c;又称视听柜&#xff0c;随着生活水平的提高&#xff0c;与电视机相配套的电器设备也成为电视柜的收纳对象。 随着智能家具的发展&#xff0c;智能电视机柜的造型和风格都是有了…

2023/10/1 -- ARM

今日任务&#xff1a;select实现服务器并发 ser.c&#xff1a; #include <myhead.h>#define ERR_MSG(msg) do{\printf("%d\n",__LINE__);\perror(msg);\ }while(0)#define PORT 8888#define IP "192.168.1.5"int main(int argc, const char *argv[…

Java中DateTimeFormatter的使用方法和案例

&#x1f514;简介 在Java中,DateTimeFormatter类用于格式化和解析日期时间对象。它是日期时间格式化的强大而灵活的工具。 &#x1f514;作用 &#x1f335;1.本地化时间 本地化时间指根据指定的语言环境显示时间 1.1.创建DateTimeFormatter时指定Locale DateTimeFormatt…

ORA-01034: ORACLE not available?一文解决

1.情况描述 oracle用户sqlplus登陆数据库&#xff08;11gR2 单机asm&#xff09;&#xff0c;进去查询一些基本的视图发现报错 ORA-01034: ORACLE not available&#xff0c;详细如下 [oracleoomcserver db_1]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production…

ClassNotFoundException与NoClassDefFoundError

如果这springboot服务启动时两个报错同时出现&#xff0c;那大概率是依赖间冲突导致的 查资料发现是springcloud的依赖版本和springboot的依赖版本不兼容&#xff0c;顺藤摸瓜找到springcloud jar包中调用org.springframework.boot.context.properties.ConfigurationProperties…

酷开科技OTT大屏营销,做好价值塑造

洞察2023&#xff0c;随着技术与数据入局OTT领域&#xff0c;程序化投放、数据追踪、人群定位等等能力正逐步深入&#xff0c;围绕OTT大屏营销&#xff0c;新营销的价值也正在被重构。随着国内5G、人工智能、云计算等技术不断普及&#xff0c;大屏营销服务成为OTT行业发展的主流…

笔试强训Day9

T1&#xff1a;走方格的方案数 链接&#xff1a;走方格的方案数_牛客题霸_牛客网 (nowcoder.com) 描述 请计算n*m的棋盘格子&#xff08;n为横向的格子数&#xff0c;m为竖向的格子数&#xff09;从棋盘左上角出发沿着边缘线从左上角走到右下角&#xff0c;总共有多少种走法…

SpringCloud Alibaba - Sentinel 微服务保护解决雪崩问题、Hystrix 区别、安装及使用

目录 一、Sentinel 1.1、背景&#xff1a;雪崩问题 1.2、雪崩问题的解决办法 1.2.1、超时处理 缺陷&#xff1a;为什么这里只是 “缓解” 雪崩问题&#xff0c;而不是百分之百解决了雪问题呢&#xff1f; 1.2.2、舱壁模式 缺陷&#xff1a;资源浪费 1.2.3、熔断降级 1.…

【汇编的救赎】汇编语言入门必看基本知识点

汇编语言是一种低级语言&#xff0c;用于编写计算机程序。它直接操作计算机硬件&#xff0c;提供了对处理器寄存器、内存和指令等底层资源的直接访问。汇编语言的语法简单明了&#xff0c;每条指令都对应着一条机器指令&#xff0c;具有高度的灵活性和效率。通过汇编语言&#…

MySQL SQL性能分析(SQL优化 一)

在开发和维护数据库应用程序时&#xff0c;优化SQL查询的性能是至关重要的。MySQL提供了一些强大的工具和技术&#xff0c;帮助我们进行SQL性能分析&#xff0c;找出潜在的瓶颈并进行相应的优化。 查看SQL的执行频率 show [ session| global ] status 命令查看服务器状态信息…

web:[RoarCTF 2019]Easy Calc

题目 进入页面是一个计算器的页面 随便试了一下 查看源代码看看有什么有用的信息 访问一下这个calc.php 进行代码审计 <?php error_reporting(0); if(!isset($_GET[num])){show_source(__FILE__); }else{$str $_GET[num];$blacklist [ , \t, \r, \n,\, ", , \[, \]…

Python语言:函数的使用

按我的理解&#xff0c;编程世界中的函数就是一个模块&#xff1a;提前写好一个特动功能&#xff0c;方便以后直接调用且实现其功能&#xff0c;可以大大提高工作效率。 今天我们通过一个python语言的函数使用小案例来进一步加深对函数的理解。案例名字为S的银行之行。S是一个吝…

1.6.C++项目:仿muduo库实现并发服务器之channel模块的设计

项目完整版在&#xff1a; 文章目录 一、channel模块&#xff1a;事件管理Channel类实现二、提供的功能三、实现思想&#xff08;一&#xff09;功能&#xff08;二&#xff09;意义&#xff08;三&#xff09;功能设计 四、代码&#xff08;一&#xff09;框架&#xff08;二…

Mac卸载不了软件怎么办?2023年最新MacBook卸载大集合

很多朋友在卸载软件的时候&#xff0c;可能会遇到卸载不了的情况。软件正在使用、软件来自第三方等原因都可能导致我们无法将其成功卸载。本篇文章就将告诉您“Mac卸载不了软件”的解决办法。 为什么Mac卸载不了软件&#xff1f; Mac卸载不了软件的原因很多&#xff0c;常见的…

Excel如何快速将表格纵向数据变成横向

第一&#xff0c;打开Excel文件&#xff0c;我们看到表格里面的内容为纵向排列&#xff1b; 第二&#xff0c;要将表格纵向排列变成横向&#xff0c;首先选中单元格内容&#xff0c;按CTRLC快速复制。 第三&#xff0c;选中一个空白单元格&#xff0c;点击鼠标右键&#xff0c;…

SentenceTransformer 之论文解读

摘要 原文标题&#xff1a;Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks 链接&#xff1a;https://arxiv.org/pdf/1908.10084.pdf 尽管Bert和RoBERTa在句子对回归任务上&#xff0c;例如语义文本相似度&#xff08;Semantic Text Similarity&#xff09;…