![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f6a70672f69634670384d464f34494b796a6e774e30784578394d38685751744f6d434435676a446161784c555278597969633970793076416d7968527667696232686e59493139436961744b6c576d546c794d5a3769633954383148525a772f3634303f77785f666d743d6a706567.webp)
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f6769662f3876704247344b494e514d744431765565627749377a37333377507044636d746962427a67557a6a6235536765755071576e38776d4f4f6f46596961564d467572655379586356356e4a44586138444b6b6d653546346d672f3634303f77785f666d743d676966.webp)
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f706e672f69634670384d464f34494b7733653237307476523475745a43626c4a706962386562574c72797038365456654c4c30514a416a6538385573653242586d69624448374a5269633030477276384754447536724b6b3245384834672f3634303f77785f666d743d706e67.webp)
怎麼學?
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f706e672f69634670384d464f34494b7733653237307476523475745a43626c4a706962386562574c72797038365456654c4c30514a416a6538385573653242586d69624448374a5269633030477276384754447536724b6b3245384834672f3634303f77785f666d743d706e67.webp)
To Do App
整個項目的代碼我已經寫完了,它的結構非常簡單,一共就只有三個頁面:
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f706e672f3876704247344b494e514d744431765565627749377a37333377507044636d743768456f72336178634a4b4b70316a69614a5051635a456570396d36416644435277754f383469635776647067616962383871336b69614d68672f3634303f77785f666d743d706e67.webp)
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f706e672f69634670384d464f34494b7733653237307476523475745a43626c4a706962386562574c72797038365456654c4c30514a416a6538385573653242586d69624448374a5269633030477276384754447536724b6b3245384834672f3634303f77785f666d743d706e67.webp)
工程介紹
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f706e672f3876704247344b494e514d744431765565627749377a37333377507044636d7451474a733556744a6b574857373836674765466c56734c62696150696376437939713434315932544e4b416b463176306b7a5964736a30772f3634303f77785f666d743d706e67.webp)
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f706e672f69634670384d464f34494b7733653237307476523475745a43626c4a706962386562574c72797038365456654c4c30514a416a6538385573653242586d69624448374a5269633030477276384754447536724b6b3245384834672f3634303f77785f666d743d706e67.webp)
開屏頁面
其中,最簡單的,就是 Splash 頁面,它的作用只有一個:展示 Logo,接着等待一小會,進入首頁。在這裡,我們會實現一個動畫。
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f6769662f3876704247344b494e514d744431765565627749377a37333377507044636d746962427a67557a6a6235536765755071576e38776d4f4f6f46596961564d467572655379586356356e4a44586138444b6b6d653546346d672f3634303f77785f666d743d676966.webp)
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f706e672f69634670384d464f34494b7733653237307476523475745a43626c4a706962386562574c72797038365456654c4c30514a416a6538385573653242586d69624448374a5269633030477276384754447536724b6b3245384834672f3634303f77785f666d743d706e67.webp)
首頁
接着,我們來看看首頁的功能,它會展示當前所有的任務和狀態。
這裡,我寫了一個進場動效,這個在 Compose 當中實現起來真沒什麼難度。
拖拽刪除
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f6769662f3876704247344b494e514d744431765565627749377a37333377507044636d7467434e76473067364b7a5a613975546143514a334c6f59696237574a4a4b787573414271386d4c764d5635793246644468614b6963534f512f3634303f77785f666d743d67696626616d703b777866726f6d3d3526616d703b77785f6c617a793d31.webp)
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f706e672f69634670384d464f34494b7733653237307476523475745a43626c4a706962386562574c72797038365456654c4c30514a416a6538385573653242586d69624448374a5269633030477276384754447536724b6b3245384834672f3634303f77785f666d743d706e67.webp)
任務詳情頁面
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f706e672f69634670384d464f34494b7733653237307476523475745a43626c4a706962386562574c72797038365456654c4c30514a416a6538385573653242586d69624448374a5269633030477276384754447536724b6b3245384834672f3634303f77785f666d743d706e67.webp)
Splash 代碼
OK,工程介紹完了,我們就可以上代碼了!這篇文章,我們先從最簡單的 Splash 頁面開始吧!
@ComposablefunSplash(offsetState:Dp,alphaState:Float){//1Box(modifier=Modifier.fillMaxSize().background(MaterialTheme.colors.splashBackground),contentAlignment=Alignment.Center){//2Column(horizontalAlignment=Alignment.CenterHorizontally){//3Image(modifier=Modifier.size(LOGO_HEIGHT).alpha(alpha=alphaState),painter=painterResource(id=getLogo()),contentDescription=stringResource(id=R.string.to_do_logo))//4Text(modifier=Modifier.offset(y=offsetState).alpha(alpha=alphaState),text=stringResource(id=R.string.app_name),color=MaterialTheme.colors.splashText,style=MaterialTheme.typography.h5,fontWeight=FontWeight.Bold,maxLines=1,)}}}
OK,UI 元素寫出來了,動畫怎麼搞?
@ComposablefunSplash(gotoHomeScreen:()->Unit){//1varstartbyremember{mutableStateOf(false)}//2valoffsetbyanimateDpAsState(targetValue=if(start)0.dpelse100.dp,animationSpec=tween(durationMillis=1000))valalphabyanimateFloatAsState(targetValue=if(start)1felse0f,animationSpec=tween(durationMillis=2000))//3LaunchedEffect(key1=Unit){start=truedelay(SPLASH_DELAY)gotoHomeScreen()}Splash(offsetState=offset,alphaState=alpha)}
其實,動畫也很簡單,我們通過注釋來看:
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f6769662f3876704247344b494e514d744431765565627749377a37333377507044636d746962427a67557a6a6235536765755071576e38776d4f4f6f46596961564d467572655379586356356e4a44586138444b6b6d653546346d672f3634303f77785f666d743d676966.webp)
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f706e672f69634670384d464f34494b7733653237307476523475745a43626c4a706962386562574c72797038365456654c4c30514a416a6538385573653242586d69624448374a5269633030477276384754447536724b6b3245384834672f3634303f77785f666d743d706e67.webp)
結束語
恭喜您,您已經完成了一個 Compose 頁面!
長按右側二維碼
查看更多開發者精彩分享
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f706e672f69634670384d464f34494b79657a5a5253654e4f596831466c4d5753676c37504c42576e44363077336444427a4f7237686f35523263596744384879594a566379656457664831504e4a6449535036566b5139493379512f3634303f77785f666d743d706e67.webp)
"開發者說·DTalk" 面向中國開發者們徵集 Google 移動應用 (apps & games)相關的產品/技術內容。歡迎大家前來分享您對移動應用的行業洞察或見解、移動開發過程中的心得或新發現、以及應用出海的實戰經驗總結和相關產品的使用反饋等。我們由衷地希望可以給這些出眾的中國開發者們提供更好展現自己、充分發揮自己特長的平台。我們將通過大家的技術內容着重選出優秀案例進行谷歌開發技術專家 (GDE)的推薦。
點擊屏末|閱讀原文|即刻報名參與"開發者說·DTalk"
![](https://imageproxy.pixnet.cc/imgproxy?url=https://drbanana.ml/img/68747470733a2f2f6d6d62697a2e717069632e636e2f6d6d62697a5f706e672f69634670384d464f34494b78527535564d5536396963517a416477524d5071696350304b716e6b56706e69626f776963436b676961486e41447a534f4939305a3774654b6e55704d6f31776961386d326b685a5369624e5455746a4c67512f3634303f77785f666d743d706e6726616d703b777866726f6d3d3526616d703b77785f6c617a793d3126616d703b77785f636f3d31.webp)