使用Jetpack Compose實(shí)現(xiàn)翻轉(zhuǎn)卡片效果流程詳解
如何使用 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)文章
android 中使用TableLayout實(shí)現(xiàn)表單布局效果示例
本篇文章主要介紹了android 中使用TableLayout實(shí)現(xiàn)表單布局效果示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-06-06Listview中Button搶占焦點(diǎn)的解決方法
在程序開(kāi)發(fā)中經(jīng)常見(jiàn)到listview button搶占焦點(diǎn)的問(wèn)題,怎么回事什么原因呢?下面小編給大家?guī)?lái)了Listview中Button搶占焦點(diǎn)的解決方法,感興趣的朋友一起看下吧2016-08-08Android基于socket實(shí)現(xiàn)的簡(jiǎn)單C/S聊天通信功能
這篇文章主要介紹了Android基于socket實(shí)現(xiàn)的簡(jiǎn)單C/S聊天通信功能,結(jié)合實(shí)例形式分析了Android使用socket實(shí)現(xiàn)客服端與服務(wù)器端數(shù)據(jù)的發(fā)送與接收處理技巧,需要的朋友可以參考下2016-10-10Android App中的多個(gè)LinearLayout嵌套布局實(shí)例解析
這篇文章主要介紹了Android App中的多個(gè)LinearLayout嵌套布局實(shí)例,利用線性布局來(lái)排列按鈕是安卓應(yīng)用布局中的常用做法,需要的朋友可以參考下2016-04-04Android嵌套滾動(dòng)的傳統(tǒng)方法與思路
Android嵌套滾動(dòng)是在開(kāi)發(fā)中經(jīng)常遇到的一個(gè)需求,這篇文章主要介紹了Android嵌套滾動(dòng)的傳統(tǒng)方法與思路的相關(guān)資料,對(duì)各位Android開(kāi)發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05Flutter permission_handler 權(quán)限插件的使用詳解
這篇文章主要介紹了Flutter permission_handler 權(quán)限插件的使用,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04超簡(jiǎn)單Android集成華為HMS Scankit 掃碼SDK實(shí)現(xiàn)掃一掃二維碼
這篇文章主要介紹了超簡(jiǎn)單Android集成華為HMS Scankit 掃碼SDK實(shí)現(xiàn)掃一掃二維碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03Android控件之CheckBox、RadioButton用法實(shí)例分析
這篇文章主要介紹了Android控件之CheckBox、RadioButton用法,以實(shí)例形式較為詳細(xì)的分析了CheckBox和RadioButton實(shí)現(xiàn)復(fù)選按鈕及單選按鈕功能的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09Android編程之界面跳動(dòng)提示動(dòng)畫(huà)效果實(shí)現(xiàn)方法
這篇文章主要介紹了Android編程之界面跳動(dòng)提示動(dòng)畫(huà)效果實(shí)現(xiàn)方法,實(shí)例分析了Android動(dòng)畫(huà)效果的布局及功能相關(guān)實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11