欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

先上效果圖

源碼 github.com/woshiwzy/Ca…

實(shí)現(xiàn)原理:

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

思路:

1.用Bounds 對(duì)象記錄每一個(gè)CardView 對(duì)象的初始位置,當(dāng)前位置,運(yùn)動(dòng)目標(biāo)位置

2.點(diǎn)擊時(shí)計(jì)算出對(duì)應(yīng)的view以及可能會(huì)產(chǎn)生關(guān)聯(lián)運(yùn)動(dòng)的View的運(yùn)動(dòng)的目標(biāo)位置,從當(dāng)前位置運(yùn)動(dòng)到目標(biāo)位置,然后以這2個(gè)位置作為動(dòng)畫參數(shù)實(shí)施ValueAnimator動(dòng)畫,在動(dòng)畫回調(diào)中觸發(fā)onLayout,達(dá)到動(dòng)畫的效果。

重寫adView 方法

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

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

確保每個(gè)子View的測(cè)量屬性寬度填滿父組件

    boolean mesured = false;
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        if (mesured == true) {//只需要測(cè)量一次
            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 方法是關(guān)鍵

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

@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…

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

相關(guān)文章

最新評(píng)論