帶有動(dòng)畫效果的注冊(cè)控件

帶有動(dòng)畫效果的注冊(cè)控件
代碼下載

signup.png
signup.gif

一共有4個(gè)動(dòng)畫效果
1,點(diǎn)擊sign up轉(zhuǎn)變成輸入框
2,點(diǎn)擊下一步
3,最后一步歡迎文字漸變
4,輸入框非法抖動(dòng)效果
canvas 畫板
1,drawBg(canvas);
2,drawTitleAndText(canvas);
3,drawGoButton(canvas);
因?yàn)槭抢^承了EditText,所以要監(jiān)聽onTextChanged,來重新繪制。如果文字超出view的寬度要將背景進(jìn)行平移,如果文字在view寬度內(nèi),隨文字長(zhǎng)度顯示寬度

        textWidth = getPaint().measureText(getText().toString().trim());
        float marLeft = 0f;


        if (mWidth - 2 * mPadding < textWidth) {
            marLeft = textWidth - mWidth;
            bgRectF.left = mPadding + marLeft;
            bgRectF.top = mPadding;
            bgRectF.right = mWidth - mPadding + marLeft;
            bgRectF.bottom = mHeight - mPadding;
            bgPaint.setStyle(Paint.Style.FILL);
            bgPaint.setColor(bgColor);
            canvas.drawRoundRect(bgRectF, bgRectF.height() / 2, bgRectF.height() / 2, bgPaint);
            bgPaint.setStyle(Paint.Style.STROKE);
            if (inputError)
                bgPaint.setColor(errorColor);
            else
                bgPaint.setColor(Color.WHITE);

            canvas.drawRoundRect(bgRectF, bgRectF.height() / 2, bgRectF.height() / 2, bgPaint);
        } else if (mWidth / 2 >= textWidth) {

            bgRectF.left = mWidth / 2 - mWidth / 4;
            bgRectF.right = mWidth / 2 + mWidth / 4;
            float w = 0f;
            if (mStep == 1) {
                w = (bgRectF.width() - bgRectF.height()) / 2 * (interpolatedTimeFirst);
                bgRectF.left = mWidth / 2 - mWidth / 4 + w;
                bgRectF.right = mWidth / 2 + mWidth / 4 - w;

            } else {//if (mStep == 2) {
                bgRectF.left = mWidth / 2 - mWidth / 4 - textWidth / 2f;
                bgRectF.right = mWidth / 2 + mWidth / 4 + textWidth / 2f;

            }

            bgRectF.top = mPadding;
            bgRectF.bottom = mHeight - mPadding;
            bgPaint.setStyle(Paint.Style.FILL);
            bgPaint.setColor(bgColor);
            canvas.drawRoundRect(bgRectF, bgRectF.height() / 2, bgRectF.height() / 2, bgPaint);
            bgPaint.setStyle(Paint.Style.STROKE);
            if (inputError)
                bgPaint.setColor(errorColor);
            else
                bgPaint.setColor(Color.WHITE);
            canvas.drawRoundRect(bgRectF, bgRectF.height() / 2, bgRectF.height() / 2, bgPaint);


        } else {
            marLeft = 0;
            bgRectF.left = mPadding + marLeft;
            bgRectF.top = mPadding;
            bgRectF.right = mWidth - mPadding + marLeft;
            bgRectF.bottom = mHeight - mPadding;
            bgPaint.setStyle(Paint.Style.FILL);
            bgPaint.setColor(bgColor);
            canvas.drawRoundRect(bgRectF, bgRectF.height() / 2, bgRectF.height() / 2, bgPaint);
            bgPaint.setStyle(Paint.Style.STROKE);

            if (inputError)
                bgPaint.setColor(errorColor);
            else
                bgPaint.setColor(Color.WHITE);
            canvas.drawRoundRect(bgRectF, bgRectF.height() / 2, bgRectF.height() / 2, bgPaint);
        }


如果文字超出最長(zhǎng)寬度的距離,只顯示能容納最大字?jǐn)?shù)的字符串后幾位。

        canvastextlength = bgRectF.width() - bgRectF.height() * 2 - 10;
            if (canvastextlength < textWidth) {
            int count = (int) (textcount * canvastextlength / textWidth);
            canvasText = getText().toString().trim().substring(textcount - count);
            if (MInputType == InputType.EDITTEXT) {
                canvas.drawText(canvasText, bgRectF.centerX() - getFontlength(textPaint, canvasText) / 2f,
                        bgRectF.centerY() + getFontHeight(textPaint, canvasText) / 2, textPaint);
            } }
        } 

簡(jiǎn)單的抖動(dòng)動(dòng)畫

           TranslateAnimation errorAnim = new TranslateAnimation(-3,
                    3, 0, 0);
            errorAnim.setInterpolator(new CycleInterpolator(2f));
            errorAnim.setDuration(400);

使用方式

        mSignUpInputView.setBgPaintColor(Color.BLACK);
        mSignUpInputView.setTextPaintColor(Color.WHITE);
        mSignUpInputView.setTitlePaintColor(Color.GRAY);
        mSignUpInputView.setSetpIcon(R.mipmap.user, R.mipmap.email, R.mipmap.pwd);//set icon
        mSignUpInputView.setSetpName("Name", "Email", "PassWord");//set title
        mSignUpInputView.setmButtonText("Sign up");//button text
        mSignUpInputView.setVerifyTypeStep(SignUpInputView.VerifyType.NULL,
                SignUpInputView.VerifyType.EMAIL,
                SignUpInputView.VerifyType.PASSWORD);
         mSignUpInputView.setOnGetStepInfo(new SignUpInputView.GetStepAndText() {
            @Override
            public void GetInfo(int step, String stepName, String text) {

            }
        });

代碼下載

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,811評(píng)論 25 708
  • ¥開啟¥ 【iAPP實(shí)現(xiàn)進(jìn)入界面執(zhí)行逐一顯】 〖2017-08-25 15:22:14〗 《//首先開一個(gè)線程,因...
    小菜c閱讀 6,497評(píng)論 0 17
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 12,180評(píng)論 4 61
  • 與歷史不同的白露! 首先給大家普及一個(gè)知識(shí)白露不是一種動(dòng)物,而是一種節(jié)氣,也是一種自然現(xiàn)象! 說話說得好白鷺天朗氣...
    應(yīng)枘宇閱讀 516評(píng)論 1 0
  • 這篇文章寫于即將奔赴新生活的一個(gè)節(jié)點(diǎn),獻(xiàn)給努力生活的你: 玉泉路的倒數(shù)第某個(gè)深夜,大部分京外的同學(xué)已經(jīng)離開,月亮照...
    安與魚閱讀 402評(píng)論 0 1