示例#1
0
		private void EnsureChildren() {
	        mRulerView = FindViewById<TimeRulerView>(Resource.Id.blocks_ruler);
	        if (mRulerView == null) {
	            throw new Exception("Must include a Resource.Id.blocks_ruler view.");
	        }
	        mRulerView.DrawingCacheEnabled = true;
	
	        mNowView = FindViewById(Resource.Id.blocks_now);
	        if (mNowView == null) {
	            throw new Exception("Must include a Resource.Id.blocks_now view.");
	        }
	        mNowView.DrawingCacheEnabled = true;
	    }
        private void EnsureChildren()
        {
            mRulerView = FindViewById <TimeRulerView>(Resource.Id.blocks_ruler);
            if (mRulerView == null)
            {
                throw new Exception("Must include a Resource.Id.blocks_ruler view.");
            }
            mRulerView.DrawingCacheEnabled = true;

            mNowView = FindViewById(Resource.Id.blocks_now);
            if (mNowView == null)
            {
                throw new Exception("Must include a Resource.Id.blocks_now view.");
            }
            mNowView.DrawingCacheEnabled = true;
        }
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            EnsureChildren();

            TimeRulerView rulerView   = mRulerView;
            int           headerWidth = rulerView.GetHeaderWidth();
            int           columnWidth = (Width - headerWidth) / mColumns;

            rulerView.Layout(0, 0, Width, Height);

            int count = ChildCount;

            for (int i = 0; i < count; i++)
            {
                View child = GetChildAt(i);
                if (child.Visibility == ViewStates.Gone)
                {
                    continue;
                }

                if (child is BlockView)
                {
                    BlockView blockView = (BlockView)child;
                    int       top       = rulerView.GetTimeVerticalOffset(blockView.GetStartTime());
                    int       bottom    = rulerView.GetTimeVerticalOffset(blockView.GetEndTime());
                    int       left      = headerWidth + (blockView.GetColumn() * columnWidth);
                    int       right     = left + columnWidth;
                    child.Layout(left, top, right, bottom);
                }
            }

            // Align now view to match current time
            View nowView = mNowView;
            long now     = UIUtils.GetCurrentTime(Context);

            int top2    = rulerView.GetTimeVerticalOffset(now);
            int bottom2 = top2 + nowView.MeasuredHeight;
            int left2   = 0;
            int right2  = Width;

            nowView.Layout(left2, top2, right2, bottom2);
        }