最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用Jetpack Compose實(shí)現(xiàn)翻轉(zhuǎn)卡片效果流程詳解

 更新時(shí)間:2023年05月08日 10:45:02   作者:Calvin880828  
Jetpack Compose 是一款基于 Kotlin 的聲明式 UI 工具包,可以方便地創(chuàng)建漂亮的用戶界面。使用 Compose 的動(dòng)畫(huà) API 和可繪制 API,可以輕松實(shí)現(xiàn)翻轉(zhuǎn)卡片效果。通過(guò)設(shè)置旋轉(zhuǎn)角度和透明度等屬性,可以使卡片沿著 Y 軸翻轉(zhuǎn),并實(shí)現(xiàn)翻頁(yè)效果

如何使用 Jetpack Compose 創(chuàng)建翻轉(zhuǎn)卡片效果

介紹

在電子商務(wù)和銀行應(yīng)用程序中輸入卡信息是很常見(jiàn)的情況。我認(rèn)為讓用戶更輕松地處理這種情況并創(chuàng)建更吸引眼球的 UI 將很有用。大多數(shù)應(yīng)用程序/網(wǎng)站都喜歡它。

執(zhí)行

在開(kāi)發(fā)階段,您需要做的是打開(kāi)一個(gè) Android 項(xiàng)目并實(shí)施 Compose 庫(kù)。

如果我們繼續(xù)編碼,我們可以檢查以下 Compose 代碼。

您可以根據(jù)上面的設(shè)計(jì)在屏幕上創(chuàng)建您的卡片。

@Composable
fun AddCreditCard(backgroundColor: Color) {
    var rotated by remember { mutableStateOf(false) }
    val cardType =
        when (result.value?.organization) {
            "MasterCard" -> painterResource(R.drawable.mc)
            "VISA" -> painterResource(R.drawable.visa)
            else -> painterResource(R.drawable.ic_launcher_background)
        }
    val rotation by animateFloatAsState(
        targetValue = if (rotated) 180f else 0f,
        animationSpec = tween(500)
    )
    val animateFront by animateFloatAsState(
        targetValue = if (!rotated) 1f else 0f,
        animationSpec = tween(500)
    )
    val animateBack by animateFloatAsState(
        targetValue = if (rotated) 1f else 0f,
        animationSpec = tween(500)
    )
    Card(
        modifier = Modifier
            .height(220.dp)
            .fillMaxWidth()
            .padding(10.dp)
            .graphicsLayer {
                rotationY = rotation
                cameraDistance = 8 * density
            }
            .clickable {
                rotated = !rotated
            },
        shape = RoundedCornerShape(14.dp),
        elevation = 4.dp,
        backgroundColor = backgroundColor,
        contentColor = Color.White
    ) {
        if (!rotated) {
            Column(
                horizontalAlignment = Alignment.Start,
                verticalArrangement = Arrangement.SpaceBetween,
                modifier = Modifier.padding(start = 8.dp, end = 8.dp, bottom = 8.dp),
            ) {
                Row(horizontalArrangement = Arrangement.SpaceBetween) {
                    Icon(
                        painter = painterResource(R.drawable.ic_contactless),
                        contentDescription = "test",
                        modifier = Modifier
                            .width(50.dp)
                            .height(50.dp)
                            .padding(top = 6.dp, bottom = 6.dp, end = 20.dp)
                            .graphicsLayer {
                                alpha = animateFront
                            },
                        tint = Color.White
                    )
                    Spacer(modifier = Modifier.weight(1f))
                    Image(
                        painter = cardType,
                        contentDescription = "test",
                        modifier = Modifier
                            .width(50.dp)
                            .height(50.dp)
                            .graphicsLayer {
                                alpha = animateFront
                            }
                    )
                }
                result.value?.number?.let {
                    Text(
                        text = it,
                        modifier = Modifier
                            .padding(top = 16.dp)
                            .graphicsLayer {
                                alpha = animateFront
                            },
                        fontFamily = fontName,
                        fontWeight = FontWeight.Normal,
                        fontSize = 25.sp
                    )
                }
                Row(horizontalArrangement = Arrangement.SpaceBetween) {
                    Column(horizontalAlignment = Alignment.Start) {
                        Text(
                            text = "Card Holder",
                            color = Color.Gray,
                            fontSize = 9.sp,
                            fontWeight = FontWeight.Bold,
                            modifier = Modifier
                                .graphicsLayer {
                                    alpha = animateFront
                                }
                        )
                        Text(
                            text = "Mehmet Yozgatli",
                            color = Color.White,
                            fontSize = 15.sp,
                            fontWeight = FontWeight.Bold,
                            modifier = Modifier
                                .graphicsLayer {
                                    alpha = animateFront
                                }
                        )
                    }
                    Spacer(modifier = Modifier.weight(1f))
                    Column(horizontalAlignment = Alignment.Start) {
                        Text(
                            text = "VALID THRU",
                            color = Color.Gray,
                            fontSize = 9.sp,
                            fontWeight = FontWeight.Bold,
                            modifier = Modifier
                                .graphicsLayer {
                                    alpha = animateFront
                                }
                        )
                        result.value?.expire?.let {
                            Text(
                                text = it,
                                color = Color.White,
                                fontSize = 15.sp,
                                fontWeight = FontWeight.Bold,
                                modifier = Modifier
                                    .graphicsLayer {
                                        alpha = animateFront
                                    }
                            )
                        }
                    }
                }
            }
        } else {
            Column(
                modifier = Modifier.padding(top = 20.dp),
            ) {
                Divider(
                    modifier = Modifier
                        .graphicsLayer {
                            alpha = animateBack
                        }, color = Color.Black, thickness = 50.dp
                )
                Text(
                    text = "123",
                    color = Color.Black,
                    modifier = Modifier
                        .padding(10.dp)
                        .background(Color.White)
                        .fillMaxWidth()
                        .graphicsLayer {
                            alpha = animateBack
                            rotationY = rotation
                        }
                        .padding(10.dp),
                    fontSize = 15.sp,
                    textAlign = TextAlign.End
                )
                Text(
                    text = "Developed by Mehmet Yozgatli",
                    color = Color.White,
                    modifier = Modifier
                        .fillMaxWidth()
                        .graphicsLayer {
                            alpha = animateBack
                            rotationY = rotation
                        }
                        .padding(5.dp),
                    fontFamily = fontName,
                    fontWeight = FontWeight.Thin,
                    fontSize = 10.sp,
                    textAlign = TextAlign.Center
                )
            }
        }
    }
}

創(chuàng)建卡片后,將旋轉(zhuǎn)、animateFront 和 animateBack 值作為參數(shù)傳遞給組件時(shí),就完成了動(dòng)畫(huà)部分。

ML Kit銀行卡識(shí)別

通過(guò)使用華為機(jī)器學(xué)習(xí)服務(wù)的銀行卡識(shí)別服務(wù),您可以為用戶提供極大的便利。

您可以按照官方文檔中的實(shí)施步驟進(jìn)行操作。

https://developer.huawei.com/consumer/en/doc/development/hiai-Guides/dev-process-0000001050038076

輸出

卡片翻轉(zhuǎn)效果

使用機(jī)器學(xué)習(xí)套件獲取信息

結(jié)論

重要的是我們的應(yīng)用程序要易于使用并讓事情變得簡(jiǎn)單。

到此這篇關(guān)于使用Jetpack Compose實(shí)現(xiàn)翻轉(zhuǎn)卡片效果流程詳解的文章就介紹到這了,更多相關(guān)Jetpack Compose翻轉(zhuǎn)卡片內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

越西县| 延长县| 综艺| 彝良县| 油尖旺区| 五寨县| 盖州市| 彝良县| 鄄城县| 广宁县| 珲春市| 铁岭市| 阿坝县| 尚义县| 鞍山市| 湘乡市| 柞水县| 汽车| 景德镇市| 丹东市| 突泉县| 兴化市| 柘荣县| 宁远县| 宁都县| 周口市| 陆川县| 磐安县| 华蓥市| 武宁县| 安义县| 阿城市| 江华| 榆树市| 沂水县| 苏州市| 临猗县| 曲水县| 牟定县| 沭阳县| 昭苏县|