日历部分的代码:
package com.example.twj.qiandao; import java.util.Calendar; /** * 专用日历 * Created by t'w'j on 2020/4/21. */ public class SpecialCalendar { /** * 判断是否是闰年 */ public boolean isLeapYear(int year){ if(year%100==0&&year%400==0){ return true; }else if(year%100!=0&&year%4==0){ return true; } return false; } /** * 1 3 5 7 8 10 12,三十一天 * 4 6 9 11,三十天 * 2,二十八天 * 闰年29天 */ public int getDaysOfMonth(boolean isLeapYear,int month){ int days=0; switch (month){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: days=31; break; case 4: case 6: case 9: case 11: days=30; break; case 2: if(isLeapYear){ days=29; }else { days=28; } } return days; } /** * 得到某年某月1号是星期几 */ public int getWeekdayOfMonth(int mYear,int mMonth){ Calendar cal=Calendar.getInstance(); cal.set(mYear,mMonth,1); return cal.get(Calendar.DAY_OF_WEEK)-1; } }
package com.example.twj.qiandao; import android.content.Context; import android.util.AttributeSet; import android.widget.RelativeLayout; /** * 自定义RelativeLayout正方形 * Created by t'w'j on 2020/4/21. */ public class SquareRelativeLayout extends RelativeLayout { public SquareRelativeLayout(Context context) { super(context); } public SquareRelativeLayout(Context context, AttributeSet attrs) { super(context, attrs); } public SquareRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec)); //Children are just made to fill our space int childWithSize=getMeasuredWidth(); //高度和宽度一样 heightMeasureSpec=widthMeasureSpec=MeasureSpec.makeMeasureSpec(childWithSize,MeasureSpec.EXACTLY); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } }