黄学彪
2020-04-13 3793a9a38ac6c4c4111c2bba3a35a71c30601e82
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 做成一个里面只装FrameLayout的列表型控件(它不会调整高度,有桌布)
    /// </summary>
    public class VerticalFrameControl : VerticalScrolViewLayout
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 行之间的间距
        /// </summary>
        public int rowSpace = 0;
        /// <summary>
        /// 桌布控件
        /// </summary>
        private FrameLayout m_frameTable = null;
        /// <summary>
        /// 桌布控件
        /// </summary>
        public FrameLayout frameTable
        {
            get
            {
                if (m_frameTable == null) { this.InitFrameTable(); }
                return m_frameTable;
            }
        }
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 做成一个列表型的FrameLayout(它不会调整高度)
        /// </summary>
        /// <param name="i_rowSpace">行之间的间距(这个值是与行控件绑定一起使用的)</param>
        public VerticalFrameControl(int i_rowSpace = 0)
        {
            rowSpace = Application.GetRealHeight(i_rowSpace);
        }
 
        /// <summary>
        /// 初始化桌布控件
        /// </summary>
        private void InitFrameTable()
        {
            if (this.m_frameTable != null && this.m_frameTable.Parent != null)
            {
                return;
            }
            this.m_frameTable = new FrameLayout();
            this.m_frameTable.Width = this.Width;
            this.m_frameTable.Height = this.Height;
            this.AddChidren(this.m_frameTable);
        }
 
        #endregion
 
        #region ■ 添加子控件_________________________
 
        /// <summary>
        /// 添加Frame子控件
        /// </summary>
        /// <param name="view"></param>
        public void AddChidrenFrame(FrameLayout frame)
        {
            //初始化桌布控件
            this.InitFrameTable();
 
            var child = this.m_frameTable.GetChildren(this.m_frameTable.ChildrenCount - 1);
            if (child != null)
            {
                frame.Y = child.Bottom + rowSpace;
            }
            this.m_frameTable.AddChidren(frame);
            //调整桌布高度
            if (this.m_frameTable.Height < frame.Bottom)
            {
                this.m_frameTable.Height = frame.Bottom;
            }
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 调整子FrameLayout的高度
        /// </summary>
        /// <param name="frame"></param>
        /// <param name="buttomSpace">底部空白间距(真实值)</param>
        public void AdjustChidrenFrameHeight(FrameLayout frame, int buttomSpace)
        {
            //获取坐标底部最下面的那个控件的底部坐标
            int value = this.GetLocationMostLastViewBottom();
            if (value != -1)
            {
                //调整桌布高度
                if (frame.Height < value + buttomSpace)
                {
                    frame.Height = value + buttomSpace;
                }
            }
        }
 
        /// <summary>
        /// 调整桌布高度
        /// </summary>
        public void AdjustTableHeight()
        {
            //获取坐标底部最下面的那个控件的底部坐标
            int value = this.GetLocationMostLastViewBottom();
            if (value != -1)
            {
                //调整桌布高度
                this.m_frameTable.Height = value;
            }
        }
 
        /// <summary>
        /// 针对底部点击按钮,调整控件真实高度
        /// </summary>
        /// <param name="correctionsValue">Y轴补正值(真实值,列表控件不在bodyFramelayout的时候使用)</param>
        public void AdjustRealHeightByBottomButton(int correctionsValue = 0)
        {
            var btnTemp = new BottomClickButton();
            if (btnTemp.Yaxis >= this.m_frameTable.Height + correctionsValue)
            {
                //没有超过
                return;
            }
            //添加临时控件,直至可以滑动超过底部按钮
            var frameBackTemp = new FrameLayout();
            frameBackTemp.Height = ControlCommonResourse.BodyFrameHeight - btnTemp.Yaxis + Application.GetRealHeight(23);
            this.AddChidrenFrame(frameBackTemp);
        }
 
        /// <summary>
        /// 还原桌布高度
        /// </summary>
        public void RecoverTableHeight()
        {
            if (this.m_frameTable != null)
            {
                m_frameTable.Height = this.Height;
            }
        }
 
        /// <summary>
        /// 获取坐标底部最下面的那个控件的底部坐标
        /// </summary>
        /// <returns></returns>
        private int GetLocationMostLastViewBottom()
        {
            int bottomHeight = -1;
 
            if (this.m_frameTable == null) { return bottomHeight; }
           
            for (int i = 0; i < this.m_frameTable.ChildrenCount; i++)
            {
                var child = this.m_frameTable.GetChildren(i);
                if (child.Bottom > bottomHeight)
                {
                    bottomHeight = child.Bottom;
                }
            }
            return bottomHeight;
        }
 
        #endregion
    }
}