关于项目的一点点总结,签到返利日历的实现

突然发现之前已经有两篇博客了,最近开发了两个新项目,10.1之前上线,所以一直都很忙,新项目用到了几个知识点,所以在此总结一下,
首先做了一个签到返利效果的,在网上找了蛮多的demo,但是没有合适的,主要看了两种
我接触的两种方式
1.通过GridView 去写一个日历
2.通过自定义去画一个日历
最后我选了自定义View 不管哪一种,都需要用到DateUtils,获取年月日

(这里因为是测试库的数据,所以签到金额UI显示有问题,但是线上库的数据不是100,是0.1,0.2这样的数字,所以文字上偏移不会太大)
这里写图片描述


public class DateUtils {
    /**
     * 通过年份和月份 得到当月的日子
     * 
     * @param year
     * @param month
     * @return
     */
    public static int getMonthDays(int year, int month) {
        month++;
        switch (month) {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12: 
            return 31;
        case 4:
        case 6:
        case 9:
        case 11: 
            return 30;
        case 2:
            if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)){
                return 29;
            }else{
                return 28;
            }
        default:
            return  -1;
        }
    }
    /**
     * 返回当前月份1号位于周几
     * @param year
     *      年份
     * @param month
     *      月份,传入系统获取的,不需要正常的
     * @return
     *  日:1     一:2     二:3     三:4     四:5     五:6     六:7
     */
    public static int getFirstDayWeek(int year, int month){
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month, 1);
        Log.d("DateView", "DateView:First:" + calendar.getFirstDayOfWeek());
        return calendar.get(Calendar.DAY_OF_WEEK);
    }

}

然后就是在代码中画出来自己想要的布局
这里是先通过一个循环遍历取出一个月中的天,给每一天设置在Canvas中显示的位置,(关于自定义View,推荐扔物线大神写的一系列文章 http://hencoder.com/ui-1-5/)

这里写代码片  只给出核心代码
public class MonthDateView extends View {
     @Override
    protected void onDraw(Canvas canvas) {

        initSize();
        daysString = new int[6][7];

        mPaint.setTextSize(mDaySize * mDisplayMetrics.scaledDensity);
        String dayString;
        //日 数量 30
        int mMonthDays = DateUtils.getMonthDays(mSelYear, mSelMonth);
        //获取当前第一天 是第几周
        int weekNumber = DateUtils.getFirstDayWeek(mSelYear, mSelMonth);
        Log.d("DateView", "DateView:" + mSelMonth + "月1号周" + weekNumber);

        //这是画每一天
        for (int day = 0; day < mMonthDays; day++) {
            //dayString 就是当前date的Int 值
            dayString = (day + 1) + "";
            int column = (day + weekNumber - 1) % 7;
            int row = (day + weekNumber - 1) / 7;
            //画每一天
            daysString[row][column] = day + 1;
            int startX = (int) (mColumnSize * column + (mColumnSize - mPaint.measureText(dayString)) / 2);
            int startY = (int) (mRowSize * row + mRowSize / 2 - (mPaint.ascent() + mPaint.descent()) / 2);
            if (dayString.equals(mSelDay + "")) {
                //画 选中每一天的背景样式
                float startCirX = (float) (mColumnSize * column + mColumnSize / 2);
                float startCirY = (float) (mRowSize * row + mRowSize / 2);
                mPaint.setColor(mCircleColor);
                mPaint.setAntiAlias(true);
                canvas.drawCircle(startCirX, startCirY, 40, mPaint);
                //记录第几行,即第几周
                weekRow = row + 1;
            }


            //画有返利金额天数的背景样式 以及下面的 样式  画了很多次造成这样子的UI效果


//            drawCircle(startX, startY, row,day, canvas, dayMoney);
            drawCircle(row, column, day, canvas, dayMoney);


            if (dayString.equals(mSelDay + "")) {
                mPaint.setColor(mSelectDayColor);
            } else if (dayString.equals(mCurrDay + "") && mCurrDay != mSelDay && mCurrMonth == mSelMonth) {
                //正常月,选中其他日期,则今日为红色
                mPaint.setColor(mCurrentColor);
            } else {
                mPaint.setColor(mDayColor);
            }
            canvas.drawText(dayString, startX, startY, mPaint);
            if (tv_date != null) {
                tv_date.setText(mSelYear + "年" + (mSelMonth + 1) + "月");
            }

            if (tv_week != null) {
                tv_week.setText("第" + weekRow + "周");
            }
        }

    }



}

因为我们还需要设置一些签到之后显示的效果,所以把显示的效果在
drawCircle(int row, int column, int day, Canvas canvas, Map

 public void drawCircle(int row, int column, int day, Canvas canvas, Map<Integer, String> textMoney) {
        if (daysHasThingList != null && daysHasThingList.size() > 0) {
            //包含此天!!!!!!!!
            if (!daysHasThingList.contains(day)) return;
            if (getmSelMonth() == mCurrMonth) {

                Resources resources = getResources();

                float startCirX = (float) (mColumnSize * column + mColumnSize / 2);
                float startCirY = (float) (mRowSize * row + mRowSize / 2);


                //天数 背景 圆环  mColumnSize = 97 固定值
                int newColumn = mColumnSize * column;

                int newRow = mRowSize * row;
                Bitmap bitmap2 = BitmapFactory.decodeResource(resources, myDrawableSHape);
                int mBitWidth = bitmap2.getWidth();
                int mBitHeight = bitmap2.getHeight();
//
//                float shapeX = (float) (newColumn+ mColumnSize*0.17 );
//                float shapey = (float) (newRow +mRowSize*0.18 );
                float shapeX = (float) (newColumn+mBitWidth*0.28 );
                float shapey = (float) (newRow +mBitHeight/4 );
                mPaint.setAntiAlias(true);
                canvas.drawBitmap(bitmap2, shapeX, shapey, mPaint);


                /**
                 *TODO 重新画 很重要
                 */

//                int mBitWidth = bitmap2.getWidth();
//                int mBitHeight = bitmap2.getHeight();
//                int roundleft = newColumn;
//                int roundtop = newRow ;
//                mSrcRect = new Rect(roundleft, roundtop, mBitWidth, mBitHeight);
//                mDestRect = new Rect(roundleft, roundtop, mBitWidth, mBitHeight);
//                canvas.drawBitmap(bitmap2, mSrcRect, mDestRect, mPaint);


                //金额背景
                float circleX = (float) (mColumnSize * column + mColumnSize * 0.05);
                float circley = (float) (mRowSize * row + mRowSize * 0.7);
                mPaint.setAntiAlias(true);

                Bitmap bitmap = BitmapFactory.decodeResource(resources, myDrawable);
                canvas.drawBitmap(bitmap, circleX, circley, mPaint);
                //金额
                String money = textMoney.get(day);

//                float textY = (float) circley + mRowSize / 3;

                Paint paint1 = new Paint();
                paint1.setColor(mMoneyColor);
                paint1.setAntiAlias(true);
                paint1.setTextSize((mDaySize * mDisplayMetrics.scaledDensity / 3) * 2);
//                float textX =   (float) (mColumnSize * column + (mColumnSize - paint1.measureText(String.valueOf(day))) / 2);;
                float textX = (float) newColumn +mColumnSize/4;
                float textY = (float) ((float) circley +(float) mColumnSize *0.3);
                String newmoney ="+" + money + "元";
                canvas.drawText(newmoney, textX, textY, paint1);
            }
        }
    }

主要功能代码大概就是这样,现在贴出来全部代码

public class MonthDateView extends View {
    private static final int NUM_COLUMNS = 7;
    private static final int NUM_ROWS = 6;
    private Paint mPaint;
    private int mDayColor = Color.parseColor("#000000");
    private int mSelectDayColor = Color.parseColor("#ffffff");
    private int mSelectBGColor = Color.parseColor("#1FC2F3");
    private int mCurrentColor = Color.parseColor("#ff0000");
    private int mCurrYear, mCurrMonth, mCurrDay;
    private int mSelYear, mSelMonth, mSelDay;
    private int mColumnSize, mRowSize;
    private DisplayMetrics mDisplayMetrics;
    private int mDaySize = 16;
    private TextView tv_date, tv_week;
    private int weekRow;
    private int[][] daysString;
    private int mCircleRadius = 6;
    private DateClick dateClick;
    private int mCircleColor = Color.parseColor("#ff0000");
    private int mTextColor = Color.parseColor("#1d1d1d");
//    private int mMoneyColor = Color.parseColor("#1d1d1d");
    private int mMoneyColor = Color.parseColor("#ffffff");


    private List<Integer> daysHasThingList;
    private Map<Integer, String> dayMoney;
    private int myDrawable = R.drawable.signin_calendar_moneybg;
    private int myDrawableSHape = R.drawable.signin_calendar_round;

    private int dateTag = 0;

    public MonthDateView(Context context, AttributeSet attrs) {
        super(context, attrs);
        //density = 2.0
        mDisplayMetrics = getResources().getDisplayMetrics();
        Calendar calendar = Calendar.getInstance();
        mPaint = new Paint();
        mCurrYear = calendar.get(Calendar.YEAR);
        mCurrMonth = calendar.get(Calendar.MONTH);
        mCurrDay = calendar.get(Calendar.DATE);
        setSelectYearMonth(mCurrYear, mCurrMonth, mCurrDay);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onDraw(Canvas canvas) {

        initSize();
        daysString = new int[6][7];

        mPaint.setTextSize(mDaySize * mDisplayMetrics.scaledDensity);
        String dayString;
        //日 数量 30
        int mMonthDays = DateUtils.getMonthDays(mSelYear, mSelMonth);
        //获取当前第一天 是第几周
        int weekNumber = DateUtils.getFirstDayWeek(mSelYear, mSelMonth);
        Log.d("DateView", "DateView:" + mSelMonth + "月1号周" + weekNumber);

        //这是画每一天
        for (int day = 0; day < mMonthDays; day++) {
            //dayString 就是当前date的Int 值
            dayString = (day + 1) + "";
            int column = (day + weekNumber - 1) % 7;
            int row = (day + weekNumber - 1) / 7;
            //画每一天
            daysString[row][column] = day + 1;
            int startX = (int) (mColumnSize * column + (mColumnSize - mPaint.measureText(dayString)) / 2);
            int startY = (int) (mRowSize * row + mRowSize / 2 - (mPaint.ascent() + mPaint.descent()) / 2);
            if (dayString.equals(mSelDay + "")) {
                //画 选中每一天的背景样式
                float startCirX = (float) (mColumnSize * column + mColumnSize / 2);
                float startCirY = (float) (mRowSize * row + mRowSize / 2);
                mPaint.setColor(mCircleColor);
                mPaint.setAntiAlias(true);
                canvas.drawCircle(startCirX, startCirY, 40, mPaint);
                //记录第几行,即第几周
                weekRow = row + 1;
            }


            //画有返利金额天数的背景样式 以及下面的 样式  画了很多次造成这样子的UI效果


//            drawCircle(startX, startY, row,day, canvas, dayMoney);
            drawCircle(row, column, day, canvas, dayMoney);


            if (dayString.equals(mSelDay + "")) {
                mPaint.setColor(mSelectDayColor);
            } else if (dayString.equals(mCurrDay + "") && mCurrDay != mSelDay && mCurrMonth == mSelMonth) {
                //正常月,选中其他日期,则今日为红色
                mPaint.setColor(mCurrentColor);
            } else {
                mPaint.setColor(mDayColor);
            }
            canvas.drawText(dayString, startX, startY, mPaint);
            if (tv_date != null) {
                tv_date.setText(mSelYear + "年" + (mSelMonth + 1) + "月");
            }

            if (tv_week != null) {
                tv_week.setText("第" + weekRow + "周");
            }
        }

    }

    private Rect mSrcRect, mDestRect;

    public void drawCircle(int row, int column, int day, Canvas canvas, Map<Integer, String> textMoney) {
        if (daysHasThingList != null && daysHasThingList.size() > 0) {
            //包含此天!!!!!!!!
            if (!daysHasThingList.contains(day)) return;
            if (getmSelMonth() == mCurrMonth) {

                Resources resources = getResources();

                float startCirX = (float) (mColumnSize * column + mColumnSize / 2);
                float startCirY = (float) (mRowSize * row + mRowSize / 2);


                //天数 背景 圆环  mColumnSize = 97 固定值
                int newColumn = mColumnSize * column;

                int newRow = mRowSize * row;
                Bitmap bitmap2 = BitmapFactory.decodeResource(resources, myDrawableSHape);
                int mBitWidth = bitmap2.getWidth();
                int mBitHeight = bitmap2.getHeight();
//
//                float shapeX = (float) (newColumn+ mColumnSize*0.17 );
//                float shapey = (float) (newRow +mRowSize*0.18 );
                float shapeX = (float) (newColumn+mBitWidth*0.28 );
                float shapey = (float) (newRow +mBitHeight/4 );
                mPaint.setAntiAlias(true);
                canvas.drawBitmap(bitmap2, shapeX, shapey, mPaint);


                /**
                 *TODO 重新画 很重要
                 */

//                int mBitWidth = bitmap2.getWidth();
//                int mBitHeight = bitmap2.getHeight();
//                int roundleft = newColumn;
//                int roundtop = newRow ;
//                mSrcRect = new Rect(roundleft, roundtop, mBitWidth, mBitHeight);
//                mDestRect = new Rect(roundleft, roundtop, mBitWidth, mBitHeight);
//                canvas.drawBitmap(bitmap2, mSrcRect, mDestRect, mPaint);


                //金额背景
                float circleX = (float) (mColumnSize * column + mColumnSize * 0.05);
                float circley = (float) (mRowSize * row + mRowSize * 0.7);
                mPaint.setAntiAlias(true);

                Bitmap bitmap = BitmapFactory.decodeResource(resources, myDrawable);
                canvas.drawBitmap(bitmap, circleX, circley, mPaint);
                //金额
                String money = textMoney.get(day);

//                float textY = (float) circley + mRowSize / 3;

                Paint paint1 = new Paint();
                paint1.setColor(mMoneyColor);
                paint1.setAntiAlias(true);
                paint1.setTextSize((mDaySize * mDisplayMetrics.scaledDensity / 3) * 2);
//                float textX =   (float) (mColumnSize * column + (mColumnSize - paint1.measureText(String.valueOf(day))) / 2);;
                float textX = (float) newColumn +mColumnSize/4;
                float textY = (float) ((float) circley +(float) mColumnSize *0.3);
                String newmoney ="+" + money + "元";
                canvas.drawText(newmoney, textX, textY, paint1);
            }
        }
    }
    @Override
    public boolean performClick() {
        return super.performClick();
    }

    private int downX = 0, downY = 0;

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        int eventCode = event.getAction();
        switch (eventCode) {
            case MotionEvent.ACTION_DOWN:
                downX = (int) event.getX();
                downY = (int) event.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                int upX = (int) event.getX();
                int upY = (int) event.getY();
                if (Math.abs(upX - downX) < 10 && Math.abs(upY - downY) < 10) {//点击事件
                    performClick();
                    doClickAction((upX + downX) / 2, (upY + downY) / 2);
                }
                break;
        }
        return true;
    }

    /**
     * 初始化列宽行高
     */
    private void initSize() {
        mColumnSize = getWidth() / NUM_COLUMNS;
        mRowSize = getHeight() / NUM_ROWS;
    }

    /**
     * 设置年月
     *
     * @param year
     * @param month
     */
    private void setSelectYearMonth(int year, int month, int day) {
        mSelYear = year;
        mSelMonth = month;
        mSelDay = day;
    }

    /**
     * 执行点击事件
     *
     * @param x
     * @param y
     */
    private void doClickAction(int x, int y) {
        int row = y / mRowSize;
        int column = x / mColumnSize;
        setSelectYearMonth(mSelYear, mSelMonth, daysString[row][column]);
        invalidate();
        //执行activity发送过来的点击处理事件
        if (dateClick != null) {
            dateClick.onClickOnDate();
        }
    }

    /**
     * 左点击,日历向后翻页
     */
    public void onLeftClick() {
        int year = mSelYear;
        int month = mSelMonth;
        int day = mSelDay;
        if (month == 0) {//若果是1月份,则变成12月份
            year = mSelYear - 1;
            month = 11;
        } else if (DateUtils.getMonthDays(year, month) == day) {
            //如果当前日期为该月最后一点,当向前推的时候,就需要改变选中的日期
            month = month - 1;
            day = DateUtils.getMonthDays(year, month);
        } else {
            month = month - 1;
        }
        setSelectYearMonth(year, month, day);
        invalidate();
    }

    /**
     * 右点击,日历向前翻页
     */
    public void onRightClick() {
        int year = mSelYear;
        int month = mSelMonth;
        int day = mSelDay;
        if (month == 11) {//若果是12月份,则变成1月份
            year = mSelYear + 1;
            month = 0;
        } else if (DateUtils.getMonthDays(year, month) == day) {
            //如果当前日期为该月最后一点,当向前推的时候,就需要改变选中的日期
            month = month + 1;
            day = DateUtils.getMonthDays(year, month);
        } else {
            month = month + 1;
        }
        setSelectYearMonth(year, month, day);
        invalidate();
    }

    /**
     * 获取选择的年份
     *
     * @return
     */
    public int getmSelYear() {
        return mSelYear;
    }

    /**
     * 获取选择的月份
     *
     * @return
     */
    public int getmSelMonth() {
        return mSelMonth;
    }


    /**
     * 获取选择的日期
     *
     * @param
     */
    public int getmSelDay() {
        return this.mSelDay;
    }

    /**
     * 普通日期的字体颜色,默认黑色
     *
     * @param mDayColor
     */
    public void setmDayColor(int mDayColor) {
        this.mDayColor = mDayColor;
    }

    /**
     * 选择日期的颜色,默认为白色
     *
     * @param mSelectDayColor
     */
    public void setmSelectDayColor(int mSelectDayColor) {
        this.mSelectDayColor = mSelectDayColor;
    }

    /**
     * 选中日期的背景颜色,默认蓝色
     *
     * @param mSelectBGColor
     */
    public void setmSelectBGColor(int mSelectBGColor) {
        this.mSelectBGColor = mSelectBGColor;
    }

    /**
     * 当前日期不是选中的颜色,默认红色
     *
     * @param mCurrentColor
     */
    public void setmCurrentColor(int mCurrentColor) {
        this.mCurrentColor = mCurrentColor;
    }

    /**
     * 日期的大小,默认18sp
     *
     * @param mDaySize
     */
    public void setmDaySize(int mDaySize) {
        this.mDaySize = mDaySize;
    }

    /**
     * 设置显示当前日期的控件
     *
     * @param tv_date 显示日期
     * @param tv_week 显示周
     */
    public void setTextView(TextView tv_date, TextView tv_week) {
        this.tv_date = tv_date;
        this.tv_week = tv_week;
        invalidate();
    }

    /**
     * 设置事务天数
     *
     * @param daysHasThingList
     */
    public void setDaysHasThingList(List<Integer> daysHasThingList) {
        this.daysHasThingList = daysHasThingList;
    }


    /***
     * 设置圆圈的半径,默认为6
     *
     * @param mCircleRadius
     */
    public void setmCircleRadius(int mCircleRadius) {
        this.mCircleRadius = mCircleRadius;
    }

    /**
     * 设置圆圈的半径
     *
     * @param mCircleColor
     */
    public void setmCircleColor(int mCircleColor) {
        this.mCircleColor = mCircleColor;
    }

    /**
     * 设置日期的点击回调事件
     *
     * @author shiwei.deng
     */
    public interface DateClick {
        public void onClickOnDate();
    }

    /**
     * 设置日期点击事件
     *
     * @param dateClick
     */
    public void setDateClick(DateClick dateClick) {
        this.dateClick = dateClick;
    }

    /**
     * 跳转至今天
     */
    public void setTodayToView() {
        setSelectYearMonth(mCurrYear, mCurrMonth, mCurrDay);
        invalidate();
    }

    /*
    需要日期 需要 金额
     */
    public void setMoney(Map<Integer, String> money) {
        this.dayMoney = money;
    }
}
public class WeekDayView extends View {
    //上横线颜色
    private int mTopLineColor = Color.parseColor("#CCE4F2");
    //下横线颜色
    private int mBottomLineColor = Color.parseColor("#CCE4F2");
    //周一到周五的颜色
    private int mWeedayColor = Color.parseColor("#1d1d1d");
    //周六、周日的颜色
    private int mWeekendColor = Color.parseColor("#ff0000");
    //线的宽度
    private int mStrokeWidth = 4;
    private int mWeekSize = 14;
    private Paint paint;
    private DisplayMetrics mDisplayMetrics;
    private String[] weekString = new String[]{"日","一","二","三","四","五","六"};
    public WeekDayView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mDisplayMetrics = getResources().getDisplayMetrics();
        paint = new Paint();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);

        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);

        if(heightMode == MeasureSpec.AT_MOST){
            heightSize = mDisplayMetrics.densityDpi * 30;
        }
        if(widthMode == MeasureSpec.AT_MOST){
            widthSize = mDisplayMetrics.densityDpi * 300;
        }
        setMeasuredDimension(widthSize, heightSize);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        int width = getWidth();
        int height = getHeight();
        //进行画上下线
        paint.setStyle(Style.STROKE);
        paint.setColor(mTopLineColor);
        paint.setStrokeWidth(mStrokeWidth);
        canvas.drawLine(0, 0, width, 0, paint);

        //画下横线
        paint.setColor(mBottomLineColor);
        canvas.drawLine(0, height, width, height, paint);
        paint.setStyle(Style.FILL);
        paint.setTextSize(mWeekSize * mDisplayMetrics.scaledDensity);
        int columnWidth = width / 7;
        for(int i=0;i < weekString.length;i++){
            String text = weekString[i];
            int fontWidth = (int) paint.measureText(text);
            int startX = columnWidth * i + (columnWidth - fontWidth)/2;
            int startY = (int) (height/2 - (paint.ascent() + paint.descent())/2);
            if(text.indexOf("日") > -1|| text.indexOf("六") > -1){
                paint.setColor(mWeekendColor);
            }else{
                paint.setColor(mWeedayColor);
            }
            canvas.drawText(text, startX, startY, paint);
        }
    }

    /**
     * 设置顶线的颜色
     * @param mTopLineColor
     */
    public void setmTopLineColor(int mTopLineColor) {
        this.mTopLineColor = mTopLineColor;
    }

    /**
     * 设置底线的颜色
     * @param mBottomLineColor
     */
    public void setmBottomLineColor(int mBottomLineColor) {
        this.mBottomLineColor = mBottomLineColor;
    }

    /**
     * 设置周一-五的颜色
     * @return
     */
    public void setmWeedayColor(int mWeedayColor) {
        this.mWeedayColor = mWeedayColor;
    }

    /**
     * 设置周六、周日的颜色
     * @param mWeekendColor
     */
    public void setmWeekendColor(int mWeekendColor) {
        this.mWeekendColor = mWeekendColor;
    }

    /**
     * 设置边线的宽度
     * @param mStrokeWidth
     */
    public void setmStrokeWidth(int mStrokeWidth) {
        this.mStrokeWidth = mStrokeWidth;
    }


    /**
     * 设置字体的大小
     * @param mWeekSize
     */
    public void setmWeekSize(int mWeekSize) {
        this.mWeekSize = mWeekSize;
    }


    /**
     * 设置星期的形式
     * @param weekString
     * 默认值  "日","一","二","三","四","五","六"
     */
    public void setWeekString(String[] weekString) {
        this.weekString = weekString;
    }
}

至于在代码中调用 因为需要和服务器对接数据,服务器回传过来日期金额以及是否签到状态

 List<Integer> listDate = new ArrayList<Integer>();
    Map<Integer, String> listMoney = new HashMap<>();
  /**
     * 获取网络数据  签到日期 返利金额
     *
     * @param response
     */
    private void processTaskData(String response) {
        Type collectionType = new TypeToken<List<DataPOJO>>() {
        }.getType();
        data = (List<DataPOJO>) new Gson()
                .fromJson(response, collectionType);
        list = new ArrayList<>();
        listDate.clear();
        listMoney.clear();
        //获取服务器数据
        for (int i = 0; i < data.size(); i++) {
            String date = data.get(i).date;
            String money = data.get(i).money;
            String status = data.get(i).status;
            if (status.equals("0")) {
                listDate.add(i);
                listMoney.put(i, money);
            }
        }
        //设置签到显示
        monthDateView.setDaysHasThingList(listDate);
        monthDateView.setMoney(listMoney);
        ProgressBarUtil.dismissProgress(getActivity());
    };

这样大概就是整个签到返利效果的日历了

下面是布局的部分代码 ,因为借鉴网上的,所以修改了一下

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main12"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/standard_white"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="160dp"
        android:background="@drawable/signin_bg">

        <RelativeLayout
            android:id="@+id/task_main_click"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="@dimen/commen_30dp"
            android:background="@drawable/signin_menu_nor">

            <TextView
                android:id="@+id/task_main_profit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="@dimen/commen_50dp"
                android:text="点击签到"
                android:textColor="@color/standard_red"
                android:textSize="16sp" />

            <TextView
                android:id="@+id/task_main_time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="@dimen/commen_70dp"
                android:text="未登录"
                android:textColor="#ffa478"
                android:textSize="11sp" />

        </RelativeLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="@dimen/commen_10dp"
            android:gravity="center_horizontal"
            android:text="连续打卡天数越多,打卡奖金越高噢!"
            android:textColor="#99ffffff" />

    </RelativeLayout>
    <!-- 日历时间选择栏 -->
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="25dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="@dimen/commen_30dp"
        android:background="#ffffff"
        android:gravity="center_vertical">

        <ImageView
            android:id="@+id/iv_left"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="75dp"
            android:background="@drawable/signin_arrow_left"
            android:contentDescription="@null" />

        <ImageView
            android:id="@+id/iv_right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="75dp"
            android:background="@drawable/signin_arrow_right"
            android:contentDescription="@null" />

        <LinearLayout
            android:id="@+id/date_operator_ll"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv_today"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_marginRight="5dp"
                android:background="#FFD700"
                android:gravity="center"
                android:text="今"
                android:textColor="#ffffff"
                android:textSize="17sp"
                android:visibility="gone" />

            <TextView
                android:id="@+id/date_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:text=""
                android:textColor="@color/text_black"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/week_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:gravity="center_horizontal"
                android:text=""
                android:textColor="#93C73C"
                android:textSize="20sp"
                android:visibility="gone" />
        </LinearLayout>
    </RelativeLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="@dimen/commen_30dp"
        android:background="#ffffff"
        android:orientation="vertical">

        <io.dcloud.H53CF40A7.view.WeekDayView
            android:layout_width="match_parent"
            android:layout_height="30dp" />

        <io.dcloud.H53CF40A7.view.MonthDateView
            android:id="@+id/monthDateView"
            android:layout_width="fill_parent"
            android:layout_height="match_parent" />
    </LinearLayout>


</LinearLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值