日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
實現(xiàn)翻轉(zhuǎn)卡片的動畫效果

在Android設(shè)計中, 經(jīng)常會使用卡片元素, 正面顯示圖片或主要信息, 背面顯示詳細(xì)內(nèi)容, 如網(wǎng)易有道詞典的單詞翻轉(zhuǎn)和海底撈的食譜展示. 實現(xiàn)卡片視圖非常容易, 那么如何實現(xiàn)翻轉(zhuǎn)動畫呢?

10年積累的網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先網(wǎng)站制作后付款的網(wǎng)站建設(shè)流程,更有達(dá)孜免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

在TB吃海底撈時, 使用Pad點餐, 發(fā)現(xiàn)應(yīng)用的食譜功能使用卡片控件, 就準(zhǔn)備和大家分享一下實現(xiàn)方式. 有興趣的朋友可以去海底撈看看:)

本文源碼的GitHub下載地址

https://github.com/SpikeKing/wcl-flip-anim-demo

歡迎Follow我的GitHub: https://github.com/SpikeKing

首頁

首頁由正面和背面兩張卡片組成, 同時, 設(shè)置點擊事件flipCard.

 
 
 
 
  1.  
  2.  
  3.  
  4.     android:id="@+id/main_fl_container" 
  5.  
  6.     xmlns:android="http://schemas.android.com/apk/res/android" 
  7.  
  8.     xmlns:tools="http://schemas.android.com/tools" 
  9.  
  10.     android:layout_width="match_parent" 
  11.  
  12.     android:layout_height="match_parent" 
  13.  
  14.     android:onClick="flipCard" 
  15.  
  16.     android:paddingBottom="@dimen/activity_vertical_margin" 
  17.  
  18.     android:paddingLeft="@dimen/activity_horizontal_margin" 
  19.  
  20.     android:paddingRight="@dimen/activity_horizontal_margin" 
  21.  
  22.     android:paddingTop="@dimen/activity_vertical_margin" 
  23.  
  24.     tools:context="me.chunyu.spike.wcl_flip_anim_demo.MainActivity"> 
  25.  
  26.   
  27.  
  28.     
  29.  
  30.         layout="@layout/cell_card_back"/> 
  31.  
  32.   
  33.  
  34.     
  35.  
  36.         layout="@layout/cell_card_front"/> 
  37.  
  38.   
  39.    

邏輯, 初始化動畫和鏡頭距離.

 
 
 
 
  1. @Override 
  2.  
  3. protected void onCreate(Bundle savedInstanceState) { 
  4.  
  5.     super.onCreate(savedInstanceState); 
  6.  
  7.     setContentView(R.layout.activity_main); 
  8.  
  9.     ButterKnife.bind(this); 
  10.  
  11.   
  12.  
  13.     setAnimators(); // 設(shè)置動畫 
  14.  
  15.     setCameraDistance(); // 設(shè)置鏡頭距離 
  16.  
  17. }  

動畫

初始化右出(RightOut)和左入(LeftIn)動畫, 使用動畫集合AnimatorSet.

當(dāng)右出動畫開始時, 點擊事件無效, 當(dāng)左入動畫結(jié)束時, 點擊事件恢復(fù).

 
 
 
 
  1. // 設(shè)置動畫 
  2.  
  3. private void setAnimators() { 
  4.  
  5.     mRightOutSet = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.anim_out); 
  6.  
  7.     mLeftInSet = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.anim_in); 
  8.  
  9.   
  10.  
  11.     // 設(shè)置點擊事件 
  12.  
  13.     mRightOutSet.addListener(new AnimatorListenerAdapter() { 
  14.  
  15.         @Override public void onAnimationStart(Animator animation) { 
  16.  
  17.             super.onAnimationStart(animation); 
  18.  
  19.             mFlContainer.setClickable(false); 
  20.  
  21.         } 
  22.  
  23.     }); 
  24.  
  25.     mLeftInSet.addListener(new AnimatorListenerAdapter() { 
  26.  
  27.         @Override public void onAnimationEnd(Animator animation) { 
  28.  
  29.             super.onAnimationEnd(animation); 
  30.  
  31.             mFlContainer.setClickable(true); 
  32.  
  33.         } 
  34.  
  35.     }); 
  36.  
  37. }  

右出動畫

 
 
 
 
  1.  
  2.  
  3.  
  4.  
  5.      
  6.  
  7.     
  8.  
  9.         android:duration="@integer/anim_length" 
  10.  
  11.         android:propertyName="rotationY" 
  12.  
  13.         android:valueFrom="0" 
  14.  
  15.         android:valueTo="180"/> 
  16.  
  17.   
  18.  
  19.      
  20.  
  21.     
  22.  
  23.         android:duration="0" 
  24.  
  25.         android:propertyName="alpha" 
  26.  
  27.         android:startOffset="@integer/anim_half_length" 
  28.  
  29.         android:valueFrom="1.0" 
  30.  
  31.         android:valueTo="0.0"/> 
  32.  
  33.   

旋轉(zhuǎn)180°, 當(dāng)旋轉(zhuǎn)一半時, 卡片消失.

左入動畫

 
 
 
 
  1.  
  2.  
  3.  
  4.  
  5.   
  6.  
  7.      
  8.  
  9.     
  10.  
  11.         android:duration="0" 
  12.  
  13.         android:propertyName="alpha" 
  14.  
  15.         android:valueFrom="1.0" 
  16.  
  17.         android:valueTo="0.0"/> 
  18.  
  19.   
  20.  
  21.      
  22.  
  23.     
  24.  
  25.         android:duration="@integer/anim_length" 
  26.  
  27.         android:propertyName="rotationY" 
  28.  
  29.         android:valueFrom="-180" 
  30.  
  31.         android:valueTo="0"/> 
  32.  
  33.   
  34.  
  35.      
  36.  
  37.     
  38.  
  39.         android:duration="0" 
  40.  
  41.         android:propertyName="alpha" 
  42.  
  43.         android:startOffset="@integer/anim_half_length" 
  44.  
  45.         android:valueFrom="0.0" 
  46.  
  47.         android:valueTo="1.0"/> 
  48.  
  49.   

在開始時是隱藏, 逆向旋轉(zhuǎn), 當(dāng)旋轉(zhuǎn)一半時, 顯示卡片.

鏡頭視角

改變視角, 涉及到旋轉(zhuǎn)卡片的Y軸, 即rotationY, 需要修改視角距離.

如果不修改, 則會超出屏幕高度, 影響視覺體驗.

 
 
 
 
  1. // 改變視角距離, 貼近屏幕 
  2.  
  3. private void setCameraDistance() { 
  4.  
  5.     int distance = 16000; 
  6.  
  7.     float scale = getResources().getDisplayMetrics().density * distance; 
  8.  
  9.     mFlCardFront.setCameraDistance(scale); 
  10.  
  11.     mFlCardBack.setCameraDistance(scale); 
  12.  
  13. }  

旋轉(zhuǎn)控制

設(shè)置右出和左入動畫的目標(biāo)控件, 兩個動畫同步進(jìn)行, 并區(qū)分正反面朝上.

 
 
 
 
  1. // 翻轉(zhuǎn)卡片 
  2.  
  3. public void flipCard(View view) { 
  4.  
  5.     // 正面朝上 
  6.  
  7.     if (!mIsShowBack) { 
  8.  
  9.         mRightOutSet.setTarget(mFlCardFront); 
  10.  
  11.         mLeftInSet.setTarget(mFlCardBack); 
  12.  
  13.         mRightOutSet.start(); 
  14.  
  15.         mLeftInSet.start(); 
  16.  
  17.         mIsShowBack = true; 
  18.  
  19.     } else { // 背面朝上 
  20.  
  21.         mRightOutSet.setTarget(mFlCardBack); 
  22.  
  23.         mLeftInSet.setTarget(mFlCardFront); 
  24.  
  25.         mRightOutSet.start(); 
  26.  
  27.         mLeftInSet.start(); 
  28.  
  29.         mIsShowBack = false; 
  30.  
  31.     } 
  32.  
  33. }  

動畫效果

動畫效果非常簡單, 全部邏輯都不足50行, 這么好玩的動畫, 用起來吧.

OK, that’s all! Enjoy it!


網(wǎng)頁題目:實現(xiàn)翻轉(zhuǎn)卡片的動畫效果
分享路徑:http://www.dlmjj.cn/article/dpgshje.html