Android自定義加載動(dòng)畫-交織

Android自定義動(dòng)畫系列八,今天來分享第八個(gè)自定義Loading動(dòng)畫(IntertwineBuilder),名字就叫交織,這個(gè)動(dòng)畫效果一般,簡(jiǎn)單分享下吧。效果圖如下:

GIF有點(diǎn)大,手機(jī)流量請(qǐng)三思。

效果圖

演示效果動(dòng)畫

介紹

首先依舊是聲明,我做這些動(dòng)畫的初衷是為了學(xué)習(xí)和分享,所以希望大家可以指點(diǎn)錯(cuò)誤,讓我更好的進(jìn)步。(系列加載動(dòng)畫的截止時(shí)間:我放棄的時(shí)候)。

今天放假第一天,心還沒回來,還想玩,想玩,玩~??。

上一個(gè)動(dòng)畫鏈接:Android自定義加載動(dòng)畫-感染體

正文

與前一個(gè)動(dòng)畫相似,繼承基類 BaseBallBuilder,具體的介紹可以見上一個(gè)動(dòng)畫,或者前往Github上進(jìn)行查看(進(jìn)去了就給個(gè)star吧,??),這里簡(jiǎn)單分享下實(shí)現(xiàn)方法吧。

    @Override
    protected void initParams(Context context)
    {//參數(shù)初始化
        mBallR = getAllSize();//圓半徑
        mPath = new Path();//路徑
        initPaint(5);//畫筆
        initPoints(mBallR);//初始化圓點(diǎn)
    }

    @Override
    protected void onDraw(Canvas canvas)
    {
        drawBall(canvas);//畫圓
    }

    /**
     * 繪制小球
     *
     * @param canvas
     */
    private void drawBall(Canvas canvas)
    {
        canvas.save();
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        super.drawBall(canvas, mPath, mPaint);
        canvas.restore();
    }

下面對(duì)圓的各個(gè)點(diǎn)偏移量進(jìn)行處理,也是這個(gè)動(dòng)畫的主要方法。關(guān)注這里就行了,大概的注視都寫在旁邊了,應(yīng)該很簡(jiǎn)單的。

    @Override
    protected void computeUpdateValue(ValueAnimator animation, @FloatRange(from = 0.0, to = 1.0) float animatedValue)
    {
        switch (mCurrAnimatorState)
        {
            case 0://交織
                animation.setInterpolator(new AccelerateInterpolator());
                for (int i = 0; i < mBallPoints.size(); i++)
                {
                    CirclePoint circlePoint = mBallPoints.get(i);
                    if (2 <= i && i <= 7)
                    {//處理右下方的所有點(diǎn)
                        circlePoint.setOffsetX(-mBallR * (1 - animatedValue));
                        circlePoint.setOffsetY(-mBallR * (1 - animatedValue));
                    }
                    else
                    {
                        circlePoint.setOffsetX(mBallR * (1 - animatedValue));
                        circlePoint.setOffsetY(mBallR * (1 - animatedValue));
                    }
                }
                break;
            case 1://還原
                animation.setInterpolator(new AccelerateInterpolator());
                for (int i = 0; i < mBallPoints.size(); i++)
                {
                    CirclePoint circlePoint = mBallPoints.get(i);
                    if (2 <= i && i <= 7)
                    {//處理右下方的所有點(diǎn)
                        circlePoint.setOffsetX(-mBallR * (animatedValue));
                        circlePoint.setOffsetY(-mBallR * (animatedValue));
                    }
                    else
                    {
                        circlePoint.setOffsetX(mBallR * (animatedValue));
                        circlePoint.setOffsetY(mBallR * (animatedValue));
                    }
                }
                break;
        }
    }

    @Override
    public void onAnimationRepeat(Animator animation)
    {
        if (++mCurrAnimatorState > FINAL_STATE)
        {//還原到第一階段
            mCurrAnimatorState = 0;
            for (CirclePoint point : mBallPoints)
            {//恢復(fù)偏移量
                point.setOffsetY(0);
                point.setOffsetX(0);
            }
        }
    }

總結(jié)

小伙伴們,要是想看更多細(xì)節(jié),可以前往文章最下面的Github鏈接,如果大家覺得ok的話,希望能給個(gè)喜歡,最渴望的是在Github上給個(gè)star。謝謝了。

如果大家有什么更好的方案,或者想要實(shí)現(xiàn)的加載效果,可以給我留言或者私信我,我會(huì)想辦法實(shí)現(xiàn)出來給大家。謝謝支持。

Github:zyao89/ZCustomView

作者:Zyao89;轉(zhuǎn)載請(qǐng)保留此行,謝謝;

個(gè)人博客:https://zyao89.cn

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容