碎紙機(jī)for android

點(diǎn)子出自dribbble
swift版本
android版本
以下是效果展示

shot.png
shot1.gif
shot2.gif
shot3.gif

紙條模式的代碼

private void drawPaperSlip(Canvas canvas) {
        Path PaperSlip = new Path();
        float paperSlipwidth = rectFPaper.width() / paperSlipCount;
        float paperSlipspace = paperSlipwidth / 7f;

        float animatedValue = mAnimatedValue;
        mPaint.setColor(paperColor);
        for (int i = 0; i < randomQuadHighs.size(); i++) {
            PaperSlip.reset();
            PaperSlip.moveTo(rectFPaper.left + i * paperSlipwidth + paperSlipspace,
                    rectFPaper.bottom
            );
            PaperSlip.lineTo(rectFPaper.left + (i + 1) * paperSlipwidth - paperSlipspace,
                    rectFPaper.bottom
            );

            float paperSlipHigh = rectFPaper.height() * 2 / 3f
                    + rectFPaper.height() / 3f * randomHighs.get(i);
            float randomQuadWidth = this.randomQuadWidths.get(i) * paperSlipspace * 2.5f * animatedValue;

            if (i % 2 == 0) {
                randomQuadWidth = randomQuadWidth * -1;

            }
            float randomQuadHigh = this.randomQuadHighs.get(i) * paperSlipHigh * animatedValue;


            PaperSlip.quadTo(
                    rectFPaper.left + (i + 1) * paperSlipwidth - paperSlipspace -
                            randomQuadWidth,
                    rectFPaper.bottom + randomQuadHigh,

                    rectFPaper.left + (i + 1) * paperSlipwidth - paperSlipspace,
                    rectFPaper.bottom + paperSlipHigh
            );


            PaperSlip.lineTo(rectFPaper.left + (i) * paperSlipwidth + paperSlipspace,
                    rectFPaper.bottom + paperSlipHigh
            );
            PaperSlip.quadTo(
                    rectFPaper.left + i * paperSlipwidth + paperSlipspace -
                            randomQuadWidth,
                    rectFPaper.bottom + randomQuadHigh,


                    rectFPaper.left + i * paperSlipwidth + paperSlipspace,
                    rectFPaper.bottom
            );
            PaperSlip.close();
            canvas.drawPath(PaperSlip, mPaint);

        }

    }

紙片模式

 private void drawPaperPiece(Canvas canvas) {


        if (mAnimatedValue == 0)
            return;


        float paperPiecewidth = rectFPaper.width() / paperSlipCount;

        Path paperPiece = new Path();


        for (int i = 0; i < PaperPiecerandAngle.size(); i++) {

            int angle = (int) (PaperPiecerandAngle.get(i) * 360);

            angle = (int) (angle + 180 * mAnimatedValue);
            float radius = paperPiecewidth * 0.8f;
            if (PaperPiecerandRadius.get(i) < 0.3f) {
                PaperPiecerandRadius.set(i,0.3f);

            }
            radius = radius * PaperPiecerandRadius.get(i);

            float centerX = mPaddingLR * 3 + (getMeasuredWidth() - 6 * mPaddingLR) * PaperPiecerandX.get(i);
            float centerY = getMeasuredHeight() / 3 * PaperPiecerandY.get(i) + getMeasuredHeight() / 3

                    + mAnimatedValue * getMeasuredHeight() / 3;
            if (PaperPiecerandRadius.get(i) >= 0.3f && PaperPiecerandRadius.get(i) <= 0.4f) {
                centerY = getMeasuredHeight() / 3 * PaperPiecerandY.get(i) + getMeasuredHeight() / 3

                        + mAnimatedValue * getMeasuredHeight() / 3 * 2.8f;
            } else if (PaperPiecerandRadius.get(i) > 0.4f && PaperPiecerandRadius.get(i) <= 0.5f) {
                centerY = getMeasuredHeight() / 3 * PaperPiecerandY.get(i) + getMeasuredHeight() / 3

                        + mAnimatedValue * getMeasuredHeight() / 3 * 2.6f;
            } else if (PaperPiecerandRadius.get(i) > 0.5f && PaperPiecerandRadius.get(i) <= 0.6f) {
                centerY = getMeasuredHeight() / 3 * PaperPiecerandY.get(i) + getMeasuredHeight() / 3

                        + mAnimatedValue * getMeasuredHeight() / 3 * 2.4f;
            } else if (PaperPiecerandRadius.get(i) > 0.6f && PaperPiecerandRadius.get(i) <= 0.7f) {
                centerY = getMeasuredHeight() / 3 * PaperPiecerandY.get(i) + getMeasuredHeight() / 3

                        + mAnimatedValue * getMeasuredHeight() / 3 * 2.2f;
            } else if (PaperPiecerandRadius.get(i) > 0.7f && PaperPiecerandRadius.get(i) <= 0.8f) {
                centerY = getMeasuredHeight() / 3 * PaperPiecerandY.get(i) + getMeasuredHeight() / 3

                        + mAnimatedValue * getMeasuredHeight() / 3 * 2.4f;
            } else if (PaperPiecerandRadius.get(i) > 0.8f && PaperPiecerandRadius.get(i) <= 0.9f) {
                centerY = getMeasuredHeight() / 3 * PaperPiecerandY.get(i) + getMeasuredHeight() / 3

                        + mAnimatedValue * getMeasuredHeight() / 3 * 2.6f;
            } else if (PaperPiecerandRadius.get(i) > 0.9f) {
                centerY = getMeasuredHeight() / 3 * PaperPiecerandY.get(i) + getMeasuredHeight() / 3

                        + mAnimatedValue * getMeasuredHeight() / 3 * 2.8f;
            }


            float x = (float) ((radius) * Math.cos(angle * Math.PI / 180f));
            float y = (float) ((radius) * Math.sin(angle * Math.PI / 180f));

            paperPiece.reset();
            paperPiece.moveTo(centerX - x,
                    centerY - y

            );


            int angleBig = 0;
            if (PaperPiecerandX.get(i) > 0.7f) {
                angleBig = (int) (180 * 0.7f);
            } else if (PaperPiecerandX.get(i) < 0.3f) {
                angleBig = (int) (180 * 0.3f);
            } else {
                angleBig = (int) (180 * PaperPiecerandX.get(i));
            }
            int angleSmall = 180 - angleBig;

            angle = angle + angleBig;
            x = (float) ((radius) * Math.cos(angle * Math.PI / 180f));
            y = (float) ((radius) * Math.sin(angle * Math.PI / 180f));
            paperPiece.lineTo(centerX - x,
                    centerY - y

            );


            angle = angle + angleSmall;
            x = (float) ((radius) * Math.cos(angle * Math.PI / 180f));
            y = (float) ((radius) * Math.sin(angle * Math.PI / 180f));
            paperPiece.lineTo(centerX - x,
                    centerY - y

            );

            angle = angle + angleBig;
            x = (float) ((radius) * Math.cos(angle * Math.PI / 180f));
            y = (float) ((radius) * Math.sin(angle * Math.PI / 180f));
            paperPiece.lineTo(centerX - x,
                    centerY - y

            );
            angle = angle + angleSmall;
            x = (float) ((radius) * Math.cos(angle * Math.PI / 180f));
            y = (float) ((radius) * Math.sin(angle * Math.PI / 180f));
            paperPiece.lineTo(centerX - x,
                    centerY - y

            );




            paperPiece.close();

            int color = (Integer) evaluator.evaluate(PaperPiecerandRadius.get(i),
                    Color.rgb(180, 180, 180), paperColor
            );

            mPaint.setColor(color);
            canvas.drawPath(paperPiece, mPaint);


        }
        mPaint.setColor(paperColor);
    }

使用方式xml

<com.ldoublem.PaperShredderlib.PaperShredderView
        android:layout_width="200dp"
        android:id="@+id/ps_delete2"
        android:layout_height="220dp"
        paper:sherderBgColor="#f4c600"
        paper:sherderText="清理中"
        paper:sherderType="0"
        paper:sherderPaperEnterColor="#56abe4"
        paper:sherderTextShadow="false"
        paper:sherderTextColor="#99101010"
        paper:sherderPaperColor="#dbdbdb"
        paper:sherderProgress="false"
      />

java

       mPaperShredderView.setShrededType(PaperShredderView.SHREDEDTYPE.Piece);//紙片效果和紙條效果
       mPaperShredderView.setSherderProgress(false);
       mPaperShredderView.setTitle("清除數(shù)據(jù)");
       mPaperShredderView.setTextColor(Color.BLACK);
       mPaperShredderView.setPaperColor(Color.BLACK);
       mPaperShredderView.setBgColor(Color.WHITE);
       mPaperShredderView.setTextShadow(false);
       mPaperShredderView.setPaperEnterColor(Color.BLACK);
       mPaperShredderView.startAnim(1000);
       mPaperShredderView.stopAnim();

如果覺(jué)得還不錯(cuò)撞鹉,去github給我點(diǎn)顆星吧^^
代碼下載

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市蒲凶,隨后出現(xiàn)的幾起案子双谆,更是在濱河造成了極大的恐慌绎秒,老刑警劉巖一姿,帶你破解...
    沈念sama閱讀 218,122評(píng)論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件拖云,死亡現(xiàn)場(chǎng)離奇詭異那伐,居然都是意外死亡踏施,警方通過(guò)查閱死者的電腦和手機(jī)石蔗,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,070評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)畅形,“玉大人养距,你說(shuō)我怎么就攤上這事。” “怎么了检盼?”我有些...
    開(kāi)封第一講書人閱讀 164,491評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵须床,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我定铜,道長(zhǎng),這世上最難降的妖魔是什么怕敬? 我笑而不...
    開(kāi)封第一講書人閱讀 58,636評(píng)論 1 293
  • 正文 為了忘掉前任揣炕,我火速辦了婚禮,結(jié)果婚禮上东跪,老公的妹妹穿的比我還像新娘畸陡。我一直安慰自己,他們只是感情好虽填,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,676評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布丁恭。 她就那樣靜靜地躺著,像睡著了一般斋日。 火紅的嫁衣襯著肌膚如雪牲览。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書人閱讀 51,541評(píng)論 1 305
  • 那天恶守,我揣著相機(jī)與錄音第献,去河邊找鬼。 笑死兔港,一個(gè)胖子當(dāng)著我的面吹牛庸毫,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播衫樊,決...
    沈念sama閱讀 40,292評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼飒赃,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了橡伞?” 一聲冷哼從身側(cè)響起盒揉,我...
    開(kāi)封第一講書人閱讀 39,211評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎兑徘,沒(méi)想到半個(gè)月后刚盈,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,655評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡挂脑,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,846評(píng)論 3 336
  • 正文 我和宋清朗相戀三年藕漱,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了欲侮。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,965評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡肋联,死狀恐怖威蕉,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情橄仍,我是刑警寧澤韧涨,帶...
    沈念sama閱讀 35,684評(píng)論 5 347
  • 正文 年R本政府宣布,位于F島的核電站侮繁,受9級(jí)特大地震影響虑粥,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜宪哩,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,295評(píng)論 3 329
  • 文/蒙蒙 一娩贷、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧锁孟,春花似錦彬祖、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 31,894評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至圆恤,卻和暖如春南蓬,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背哑了。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 33,012評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留烧颖,地道東北人弱左。 一個(gè)月前我還...
    沈念sama閱讀 48,126評(píng)論 3 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像炕淮,于是被迫代替她去往敵國(guó)和親拆火。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,914評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容