안녕하세요.
안드로이드 공부를 시작한지 2개월째인 초보 프로그래머입니다.
제가 github에서 소스 코드를 받아서 하나 하나 뜯어보면서 공부를 하고 있는데요 일부 소스 코드가 이해가
안되서 질문 드립니다.
아래 코드는 Custom Calendar View 중 일부인데요
public class CalendarView extends ViewGroup {
private final String TAG = "TIME";
private final int mScreenWidth;
private final int mWidthDate;
private long mMillis;
private int mDateOfWeek;
private int mMaxtDateOfMonth;
private int mDefaultTextSize = 40;
public static String[] DAY_OF_WEEK;
public CalendarView(Context context, AttributeSet attrs) {
super(context, attrs);
mScreenWidth = getResources().getDisplayMetrics().widthPixels;
mWidthDate = mScreenWidth / 7;
//DAY_OF_WEEK = getResources().getStringArray(R.array.day_of_week);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int count = getChildCount();
int maxHeight = 0;
int maxWidth = 0;
int childState = 0;
int mLeftWidth = 0;
int rowCount = 0;
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(mMillis);
Log.d("TAG", "setTimeInMillis : " + calendar);
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() == GONE)
continue;
measureChild(child, widthMeasureSpec, heightMeasureSpec);
maxWidth += Math.max(maxWidth, child.getMeasuredHeight());
//maxWidth = maxWidth + Math.max(maxWidth, child.getMeasuredHeight())
mLeftWidth += child.getMeasuredWidth();
if ((mLeftWidth / mScreenWidth) > rowCount) {
maxHeight += child.getMeasuredHeight();
rowCount++;
} else {
maxHeight = Math.max(maxHeight, child.getMeasuredHeight());
}
childState = combineMeasuredStates(childState, child.getMeasuredState());
} // combineMeasuredStates(curState, newState) : Merge two states as return by getMeasureState()
maxHeight = (int) (Math.ceil((count + mDateOfWeek - 1) / 7d) * (mWidthDate * 0.75));
maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, MeasureSpec.AT_MOST);
setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState), resolveSizeAndState(maxHeight, expandSpec, childState << MEASURED_HEIGHT_STATE_SHIFT));
//setMeasuredDimension(measuredWidth, measuredHeight)
LayoutParams params = getLayoutParams();
//getLayoutParams :
params.height = getMeasuredHeight();
}
여기서 궁금한점이 있어서 질문 드립니다.
1. 생성자 public CalendarView(Context context, AttributeSet attrs)
에서 생성자에 들어가는 소스 코드들은 어떤게 들어가야하는지 정해진게 있나요?
구글링해보니 초기화해야하는 값들을 넣는다고 하는데 맞나요?
2. onMeasure 메소드에서 count 의 숫자는 몇인가요? log.d로 확인을 해보려고 해도
틀린부분이 있는지 log값을 확인할수 없네요. 그 밑에 for 문에 i < count가 있는데 이 count가
달력의 숫자가 들어가는 빈칸 하나하나를 의미하는 것으로 추측은 하고 있습니다.
3. 마지막으로 여기서 mLeftWidth가 의미하는게 무엇인지 감이 오질 않습니다.
처음 질문하는거라 두서없이 생각나는대로 작성하였습니다.
잘 아시는 고수분들의 도음을 간절히 요청합니다.
감사합니다.