黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
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
using Shared.Phone.UserCenter;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone
{
    /// <summary>
    /// 信息编辑控件(不建议别人使用)
    /// </summary>
    public class InformationEditorControl
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 明细列表的桌布,白色背景
        /// </summary>
        private FrameLayout detailBackFrame = null;
        /// <summary>
        /// 列表控件
        /// </summary>
        private FrameListControl listview = null;
        /// <summary>
        /// 最小高度
        /// </summary>
        private int minHeight = -1;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 初始化控件(返回的是信息容器控件)
        /// </summary>
        /// <param name="bodyFrameLayout">父控件</param>
        /// <param name="title">标题文本</param>
        /// <param name="Height">蓝湖UI里面它的高度</param>
        /// <param name="real">是否计算Height的真实值</param>
        /// <returns>信息容器控件</returns>
        public FrameListControl InitControl(FrameLayout bodyFrameLayout, string title, int Height, bool real = true)
        {
            if (real == true) { Height = Application.GetRealHeight(Height); }
            //明细列表的桌布,白色背景
            this.detailBackFrame = new FrameLayout();
            detailBackFrame.Height = Height;
            detailBackFrame.BackgroundColor = UserCenterColor.Current.White;
            detailBackFrame.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
            detailBackFrame.Gravity = Gravity.BottomCenter;
            bodyFrameLayout.AddChidren(detailBackFrame);
            this.minHeight = detailBackFrame.Height;
 
            //信息编辑
            var btnTile = new NormalViewControl(800, 60, true);
            btnTile.X = HdlControlResourse.XXLeft;
            btnTile.Y = Application.GetRealHeight(81);
            btnTile.TextSize = 15;
            btnTile.TextColor = UserCenterColor.Current.TextColor2;
            btnTile.Text = title;
            detailBackFrame.AddChidren(btnTile);
 
            //列表控件
            this.listview = new FrameListControl(12);
            listview.Y = btnTile.Bottom + Application.GetRealHeight(17);
            listview.Height = Height - btnTile.Bottom - Application.GetRealHeight(17);
            detailBackFrame.AddChidren(listview);
 
            return listview;
        }
 
        /// <summary>
        /// 完成初始化
        /// </summary>
        /// <param name="HadBottomButton">这个控件所在的界面,底部有没有保存按钮</param>
        /// <param name="mandatoryAdjustment">强制调整高度</param>
        public void FinishInitControl(bool HadBottomButton = true, bool mandatoryAdjustment = false)
        {
            if (HadBottomButton == true)
            {
                var btnFinish = new BottomClickButton();
                //让它别改变坐标
                int tempSpace = listview.rowSpace;
                listview.rowSpace = 0;
                //促使被挡住的菜单能够向上滑动
                var frameTemp = new FrameLayout();
                frameTemp.Height = HdlControlResourse.BodyFrameHeight - btnFinish.Yaxis + Application.GetRealHeight(23);
                listview.AddChidren(frameTemp);
 
                listview.rowSpace = tempSpace;
            }
 
            //调整容器高度大小
            int value = this.GetLocationMostLastViewBottom();
            if (mandatoryAdjustment == false)
            {
                if (value + Application.GetRealHeight(23) < listview.Height)
                {
                    //不需要调整
                    return;
                }
            }
            //调整大小
            listview.Height = value + Application.GetRealHeight(23);
 
            int backHeigth = listview.Bottom;
            if (minHeight > backHeigth)
            {
                //它有个最小高度
                backHeigth = minHeight;
            }
            this.detailBackFrame.Height = backHeigth;
 
            //获取listview所在的全局容器控件
            var contrFather = GetVerticalFrameControl(listview);
            //调整桌布大小
            contrFather?.AdjustTableHeight();
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 获取listview所在的全局容器控件
        /// </summary>
        /// <param name="listview"></param>
        /// <returns></returns>
        private VerticalFrameControl GetVerticalFrameControl(FrameListControl listview)
        {
            var myContr = listview.Parent;
            while (myContr != null)
            {
                if (myContr is VerticalFrameControl)
                {
                    return (VerticalFrameControl)myContr;
                }
                myContr = myContr.Parent;
            }
            return null;
        }
 
        /// <summary>
        /// 获取坐标底部最下面的那个控件的底部坐标
        /// </summary>
        /// <returns></returns>
        private int GetLocationMostLastViewBottom()
        {
            int bottomHeight = -1;
 
            for (int i = 0; i < this.listview.ChildrenCount; i++)
            {
                var child = this.listview.GetChildren(i);
                if (child.Bottom > bottomHeight)
                {
                    bottomHeight = child.Bottom;
                }
            }
            return bottomHeight;
        }
 
        #endregion
    }
}