溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

XamarinAndroid中在RecylerView子元素進(jìn)行添加/刪除操作時(shí)如何實(shí)現(xiàn)透明動(dòng)畫效果

發(fā)布時(shí)間:2021-12-03 14:18:09 來源:億速云 閱讀:98 作者:小新 欄目:移動(dòng)開發(fā)

這篇文章主要為大家展示了“XamarinAndroid中在RecylerView子元素進(jìn)行添加/刪除操作時(shí)如何實(shí)現(xiàn)透明動(dòng)畫效果”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“XamarinAndroid中在RecylerView子元素進(jìn)行添加/刪除操作時(shí)如何實(shí)現(xiàn)透明動(dòng)畫效果”這篇文章吧。

如果在RecyclerViewAnimators.Animators中沒有所需要的動(dòng)畫效果,就可以自定義一個(gè)。此時(shí),需要讓自定義的動(dòng)畫繼承BaseItemAnimator抽象類。

【示例1-2】下面以RecylerViewAnimatorsItemAnimator項(xiàng)目為基礎(chǔ),在RecylerView子元素進(jìn)行添加/刪除操作時(shí),實(shí)現(xiàn)透明動(dòng)畫效果。具體的操作步驟如下:

1)創(chuàng)建一個(gè)類文件,命名為AlphaAnimator。

2)打開AlphaAnimator.cs文件,實(shí)現(xiàn)透明度動(dòng)畫。代碼如下:

  1. using System;

  2. using System.Collections.Generic;

  3. using System.Linq;

  4. using System.Text;

  5. using Android.App;

  6. using Android.Content;

  7. using Android.OS;

  8. using Android.Runtime;

  9. using Android.Support.V4.View;

  10. using Android.Support.V7.Widget;

  11. using Android.Views;

  12. using Android.Widget;

  13. using RecyclerViewAnimators.Animators;

  14. namespace RecylerViewAnimatorsItemAnimator

  15. {

  16.     public class AlphaAnimator : BaseItemAnimator

  17.     {

  18.         public AlphaAnimator()

  19.         {

  20.         }

  21.         //添加子元素時(shí)調(diào)用的動(dòng)畫

  22.         protected override void AnimateAddImpl(RecyclerView.ViewHolder holder)

  23.         {

  24.             ViewCompat.Animate(holder.ItemView)

  25.                 .Alpha(1)

  26.                 .SetDuration(AddDuration)

  27.                 .Start();

  28.         }

  29.         //刪除子元素時(shí)調(diào)用的動(dòng)畫

  30.         protected override void AnimateRemoveImpl(RecyclerView.ViewHolder holder)

  31.         {

  32.             ViewCompat.Animate(holder.ItemView)

  33.                 .SetDuration(RemoveDuration)

  34.                 .Alpha(0)

  35.                 .Start();

  36.         }

  37.     }

  38. }

以上是“XamarinAndroid中在RecylerView子元素進(jìn)行添加/刪除操作時(shí)如何實(shí)現(xiàn)透明動(dòng)畫效果”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI