示例#1
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            int iCount = ChildCount;
            int iWidth = r - l;

            int iXPos = PaddingLeft;
            int iYPos = PaddingTop;

            for (int i = 0; i < iCount; i++)
            {
                View pChild = GetChildAt(i);
                if (pChild.Visibility != ViewStates.Gone)
                {
                    int iChildWidth          = pChild.MeasuredWidth;
                    int iChildHeight         = pChild.MeasuredHeight;
                    App.LayoutParams pParams = (App.LayoutParams)pChild.LayoutParameters;
                    if (iXPos + iChildWidth > iWidth)
                    {
                        iXPos  = PaddingLeft;
                        iYPos += m_iLineHeight;
                    }
                    pChild.Layout(iXPos, iYPos, iXPos + iChildWidth, iYPos + iChildHeight);
                    iXPos += iChildWidth + pParams.HorizontalSpacing;
                }
            }
        }
示例#2
0
        // truth be told, I have only a vague idea what most of this is doing, and I'm too tired to care...dear future me, please figure out why this works (if it works)
        protected override void OnMeasure(int iWidthMeasureSpec, int iHeightMeasureSpec)
        {
            int iWidth  = MeasureSpec.GetSize(iWidthMeasureSpec) - PaddingLeft - PaddingRight;
            int iHeight = MeasureSpec.GetSize(iHeightMeasureSpec) - PaddingTop - PaddingBottom;

            int iCount      = ChildCount;
            int iLineHeight = 0;

            int iXPos = PaddingLeft;
            int iYPos = PaddingTop;

            int iChildHeightMeasureSpec;

            if (MeasureSpec.GetMode(iHeightMeasureSpec) == MeasureSpecMode.AtMost)
            {
                iChildHeightMeasureSpec = MeasureSpec.MakeMeasureSpec(iHeight, MeasureSpecMode.AtMost);
            }
            else
            {
                iChildHeightMeasureSpec = MeasureSpec.MakeMeasureSpec(0, MeasureSpecMode.Unspecified);
            }

            for (int i = 0; i < iCount; i++)
            {
                View pChild = GetChildAt(i);
                if (pChild.Visibility != ViewStates.Gone)
                {
                    App.LayoutParams pParams = (App.LayoutParams)pChild.LayoutParameters;
                    pChild.Measure(MeasureSpec.MakeMeasureSpec(iWidth, MeasureSpecMode.AtMost), iChildHeightMeasureSpec);
                    int iChildWidth = pChild.MeasuredWidth;
                    iLineHeight = Math.Max(m_iLineHeight, pChild.MeasuredHeight + pParams.VerticalSpacing);

                    if (iXPos + iChildWidth > iWidth)
                    {
                        iXPos  = PaddingLeft;
                        iYPos += m_iLineHeight;
                    }

                    iXPos += iChildWidth + pParams.HorizontalSpacing;
                }
            }
            m_iLineHeight = iLineHeight;

            if (MeasureSpec.GetMode(iHeightMeasureSpec) == MeasureSpecMode.Unspecified)
            {
                iHeight = iYPos + iLineHeight;
            }
            else if (MeasureSpec.GetMode(iHeightMeasureSpec) == MeasureSpecMode.AtMost)
            {
                if (iYPos + iLineHeight < iHeight)
                {
                    iHeight = iYPos + iLineHeight;
                }
            }
            SetMeasuredDimension(iWidth, iHeight);
        }