Android CalendarView slowing down layout

前端 未结 6 1329
生来不讨喜
生来不讨喜 2020-12-15 06:24

This is driving me crazy. I have a fragment in my Android app which is laid out using a RelativeLayout. Problem is that for some reason it takes ages to render, about 5 seco

6条回答
  •  失恋的感觉
    2020-12-15 07:30

    I take some hours to find the answer, but not figure out why. Here is something strange, may it can help you to find the answer.

    the cpu consumption when CalendarView slow enter image description here

    The getView in WeekAdapter has a param parent that was never used.

       public View getView(int position, View convertView, ViewGroup parent) {
           WeekView weekView = null;
            if (convertView != null) {
                weekView = (WeekView) convertView;
            } else {
                weekView = new WeekView(mContext);
                android.widget.AbsListView.LayoutParams params =
                    new android.widget.AbsListView.LayoutParams(LayoutParams.WRAP_CONTENT,
                            LayoutParams.WRAP_CONTENT);
                weekView.setLayoutParams(params);
                weekView.setClickable(true);
                weekView.setOnTouchListener(this);
            }
    
            int selectedWeekDay = (mSelectedWeek == position) ? mSelectedDate.get(
                    Calendar.DAY_OF_WEEK) : -1;
            weekView.init(position, selectedWeekDay, mFocusedMonth);
    
            return weekView;
        }
    

    Looking forward the answer.

提交回复
热议问题