亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android?實現(xiàn)卡片堆疊錢包管理動畫效果

 更新時間:2022年07月21日 09:41:55   作者:Sand  
這篇文章主要介紹了Android?實現(xiàn)卡片堆疊錢包管理動畫效果,實現(xiàn)思路是在動畫回調中requestLayout?實現(xiàn)動畫效果,用Bounds?對象記錄每一個CardView?對象的初始位置,當前位置,運動目標位置,需要的朋友可以參考下

先上效果圖

源碼 github.com/woshiwzy/Ca…

實現(xiàn)原理:

1.繼承LinearLayout
2.重寫onLayout,onMeasure 方法
3.利用ValueAnimator 實施動畫
4.在動畫回調中requestLayout 實現(xiàn)動畫效果

思路:

1.用Bounds 對象記錄每一個CardView 對象的初始位置,當前位置,運動目標位置

2.點擊時計算出對應的view以及可能會產生關聯(lián)運動的View的運動的目標位置,從當前位置運動到目標位置,然后以這2個位置作為動畫參數(shù)實施ValueAnimator動畫,在動畫回調中觸發(fā)onLayout,達到動畫的效果。

重寫adView 方法

確保新添加的在這里確保所有的子view 都有一個初始化的bounds位置

   @Override
    public void addView(View child, ViewGroup.LayoutParams params) {
        super.addView(child, params);
        Bounds bounds = getBunds(getChildCount());
    }

確保每個子View的測量屬性寬度填滿父組件

    boolean mesured = false;
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        if (mesured == true) {//只需要測量一次
            return;
        }
        mesured = true;
        int childCount = getChildCount();
        int rootWidth = getWidth();
        int rootHeight = getHeight();
        if (childCount > 0) {
            View child0 = getChildAt(0);
            int modeWidth = MeasureSpec.getMode(child0.getMeasuredWidth());
            int sizeWidth = MeasureSpec.getSize(child0.getMeasuredWidth());

            int modeHeight = MeasureSpec.getMode(child0.getMeasuredHeight());
            int sizeHeight = MeasureSpec.getSize(child0.getMeasuredHeight());

            if (childCount > 0) {
                for (int i = 0; i < childCount; i++) {
                    View childView = getChildAt(i);
                    childView.measure(MeasureSpec.makeMeasureSpec(sizeWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(sizeHeight, MeasureSpec.EXACTLY));
                    int top = (int) (i * (sizeHeight * carEvPercnet));
                    getBunds(i).setTop(top);
                    getBunds(i).setCurrentTop(top);
                    getBunds(i).setLastCurrentTop(top);
                    getBunds(i).setHeight(sizeHeight);
                }

            }

        }
    }

重寫onLayout 方法是關鍵

是動畫觸發(fā)的主要目的,這里layout參數(shù)并不是寫死的,而是計算出來的(通過ValueAnimator 計算出來的)

@Override
    protected void onLayout(boolean changed, int sl, int st, int sr, int sb) {
        int childCount = getChildCount();
        if (childCount > 0) {
            for (int i = 0; i < childCount; i++) {
                View view = getChildAt(i);
                int mWidth = view.getMeasuredWidth();
                int mw = MeasureSpec.getSize(mWidth);
                int l = 0, r = l + mw;
                view.layout(l, getBunds(i).getCurrentTop(), r, getBunds(i).getCurrentTop() + getBunds(i).getHeight());
            }
        }
    }

源碼

github: github.com/woshiwzy/Ca…

到此這篇關于Android 實現(xiàn)卡片堆疊錢包管理效果(帶動畫)的文章就介紹到這了,更多相關Android 卡片堆疊錢包管理效果內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Android中Parcel用法詳解

    Android中Parcel用法詳解

    這篇文章主要介紹了Android中Parcel用法,結合實例形式較為詳細的分析了Parcel數(shù)據(jù)容器的原理與使用方法,需要的朋友可以參考下
    2016-06-06
  • Android實現(xiàn)輪播圖效果

    Android實現(xiàn)輪播圖效果

    這篇文章主要為大家詳細介紹了Android實現(xiàn)輪播圖效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-04-04
  • Android?Kotlin全面詳細類使用語法學習指南

    Android?Kotlin全面詳細類使用語法學習指南

    這篇文章主要為大家介紹了Android?Kotlin全面詳細類使用語法學習指南,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-06-06
  • android 調用系統(tǒng)的照相機和圖庫實例詳解

    android 調用系統(tǒng)的照相機和圖庫實例詳解

    android手機有自帶的照相機和圖庫,我們做的項目中有時用到上傳圖片到服務器,今天做了一個項目用到這個功能,所以把我的代碼記錄下來和大家分享,有需求的朋友可以參考下
    2012-12-12
  • Android實現(xiàn)自定義滑動刻度尺方法示例

    Android實現(xiàn)自定義滑動刻度尺方法示例

    這篇文章主要給大家介紹了關于Android實現(xiàn)自定義滑動刻度尺的相關資料,文中通過示例代碼介紹的非常詳細,對各位Android開發(fā)者們具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-04-04
  • Android 自動完成文本框的實例

    Android 自動完成文本框的實例

    下面小編就為大家分享一篇Android 自動完成文本框的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • Android 多種dialog的實現(xiàn)方法(推薦)

    Android 多種dialog的實現(xiàn)方法(推薦)

    下面小編就為大家分享一篇Android 多種dialog的實現(xiàn)方法(推薦),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • Android高仿微信對話列表滑動刪除效果

    Android高仿微信對話列表滑動刪除效果

    這篇文章主要為大家詳細介紹了Android高仿微信對話列表滑動刪除效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-08-08
  • Android自定義輪播圖效果

    Android自定義輪播圖效果

    這篇文章主要為大家詳細介紹了Android自定義輪播圖效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • 深入理解Android組件間通信機制對面向對象特性的影響詳解

    深入理解Android組件間通信機制對面向對象特性的影響詳解

    本篇文章是對Android組件間通信機制對面向對象特性的影響進行了詳細的分析介紹,需要的朋友參考下
    2013-05-05

最新評論