黄学彪
2021-01-28 1fcf2302f79f9cbea5ef17c3688311ed65cfabb4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using Shared;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace HDL_ON.Stan
{
    /// <summary>
    /// 做成一个列表型的FrameLayout(它与VerticalListControl同一性质,但是它是FrameLayout,它会改变高度)
    /// </summary>
    public class FrameListControl : FrameLayoutBase
    {
        /// <summary>
        /// 行之间的间距
        /// </summary>
        public int rowSpace = 0;
 
        /// <summary>
        /// 做成一个列表型的FrameLayout(它与VerticalListControl同一性质,但是它是FrameLayout,它会改变高度)
        /// </summary>
        /// <param name="i_rowSpace">行之间的间距(这个值是与行控件绑定一起使用的)</param>
        public FrameListControl(int i_rowSpace = 0)
        {
            rowSpace = Application.GetRealHeight(i_rowSpace);
        }
 
        /// <summary>
        /// 添加子控件
        /// </summary>
        /// <param name="view"></param>
        public override void AddChidren(View view)
        {
            if (view is FrameRowControl || view is RowLayoutControl)
            {
                //FrameRowLayout控件的时候,直接扩大它的高度
                var intBottom = this.GetLocationMostLastViewBottom();
                if (intBottom != -1)
                {
                    view.Y = intBottom;
                }
                base.AddChidren(view);
                if (rowSpace > 0)
                {
                    view.Height += rowSpace;
                }
            }
            else
            {
                //非FrameRowLayout控件的时候,计算的是坐标
                var intBottom = this.GetLocationMostLastViewBottom();
                if (intBottom != -1)
                {
                    view.Y = intBottom + rowSpace;
                }
                base.AddChidren(view);
            }
        }
 
        /// <summary>
        /// 调整真实高度
        /// </summary>
        /// <param name="bottomSpace">底部高度(非真实值)</param>
        public void AdjustRealHeight(int bottomSpace = 0)
        {
            int bottomHeight = -1;
 
            for (int i = 0; i < this.ChildrenCount; i++)
            {
                var child = this.GetChildren(i);
                if (child.Bottom > bottomHeight)
                {
                    bottomHeight = child.Bottom;
                }
            }
            if (bottomHeight != -1)
            {
                this.Height = bottomHeight + bottomSpace;
            }
        }
 
        /// <summary>
        /// 获取坐标底部最下面的那个控件的底部坐标
        /// </summary>
        /// <returns></returns>
        private int GetLocationMostLastViewBottom()
        {
            int bottomHeight = -1;
 
            for (int i = 0; i < this.ChildrenCount; i++)
            {
                var child = this.GetChildren(i);
                if (child.Bottom > bottomHeight)
                {
                    bottomHeight = child.Bottom;
                }
            }
            return bottomHeight;
        }
    }
}