黄学彪
2020-01-09 fa6bcb2e9907772480f99205f36ec2a1ce735a22
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
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 设备明细信息的列表控件(设备信息界面专用,不建议别人使用)
    /// </summary>
    public class DeviceInformationListControl : VerticalScrolViewLayout
    {
        /// <summary>
        /// 弧度的圆的一半的高度(固定)
        /// </summary>
        public int halfRoundHeigth = Application.GetRealHeight(116) / 2;
        /// <summary>
        /// 明细标题高度(固定)
        /// </summary>
        public int titleHeight = Application.GetRealHeight(60);
        /// <summary>
        /// 明细列表控件的桌布
        /// </summary>
        private FrameLayout detailBackFrame = null;
 
        /// <summary>
        /// <para>设备明细信息的列表控件(设备信息界面专用,不建议别人使用)</para>
        /// <para>请不要添加到父控件中,调用InitControl()完成初始化</para>
        /// </summary>
        public DeviceInformationListControl()
        {
        }
 
        /// <summary>
        /// 初始化控件
        /// </summary>
        /// <param name="frame">父容器,不能为null</param>
        /// <param name="bottomWhiteFrameHeight">底部白色背景控件的高度</param>
        /// <param name="listViewMaxHeight">列表控件最大的高度</param>
        /// <param name="minDetailFrameHeight">明细Frame的最小高度</param>
        /// <param name="menuRowCount">菜单的行数(不含标题)</param>
        /// <param name="appendHeight">列表控件底部附加的空白高度(不添加在这个封装控件中)</param>
        public void InitControl(FrameLayout frame, int bottomWhiteFrameHeight,
            int listViewMaxHeight, int minDetailFrameHeight, int menuRowCount, int appendHeight = 0)
        {
            //★★★★设备明细列表需要特效,估计以后我也看不懂这代码什么意思了★★★★
 
            //列表控件最大的高度
            listViewMaxHeight = listViewMaxHeight - appendHeight;
            //弧度的圆的一半的高度(固定)
            int halfRoundHeigth = Application.GetRealHeight(116) / 2;
            //明细标题高度(固定)
            int titleHeight = Application.GetRealHeight(60);
            //明细Frame的最小高度
            minDetailFrameHeight = minDetailFrameHeight - appendHeight;
            //明细Frame实际的高度(菜单数 * 行的高度 + 明细标题高度)
            int realDetailHeight = menuRowCount * ControlCommonResourse.ListViewRowHeight + titleHeight;
            if (realDetailHeight < minDetailFrameHeight)
            {
                //明细Frame实际的高度不能低于最小高度,不然白色会铺不满
                realDetailHeight = minDetailFrameHeight;
            }
            //列表控件的高度
            int listViewHeight = listViewMaxHeight;
            if (realDetailHeight + halfRoundHeigth < listViewMaxHeight)
            {
                listViewHeight = realDetailHeight + halfRoundHeigth;
            }
            //列表控件实际高度与明细最小高度的差(此值只有0,或者大于0)
            int differValue = listViewHeight - minDetailFrameHeight - halfRoundHeigth;
            //列表控件
            this.Y = ControlCommonResourse.BodyFrameHeight - listViewHeight - bottomWhiteFrameHeight - appendHeight;
            this.BackgroundColor = UserCenterColor.Current.Transparent;
            this.Height = listViewHeight;
            frame.AddChidren(this);
            //在列表控件里添加一层背景桌布
            var listViewBackFrame = new FrameLayout();
            listViewBackFrame.BackgroundColor = UserCenterColor.Current.Transparent;
            listViewBackFrame.Height = realDetailHeight + halfRoundHeigth + differValue;
            base.AddChidren(listViewBackFrame);
 
            if (differValue > 0)
            {
                //添加一个透明的东西到列表顶部
                var frameTransparent = new FrameLayout();
                frameTransparent.BackgroundColor = UserCenterColor.Current.Transparent;
                frameTransparent.Height = differValue;
                listViewBackFrame.AddChidren(frameTransparent);
            }
 
            //弧度的圆
            var btnRound = new NormalViewControl(listViewBackFrame.Width, halfRoundHeigth * 2, false);
            btnRound.Y = differValue;
            btnRound.BackgroundColor = UserCenterColor.Current.White;
            btnRound.Radius = (uint)halfRoundHeigth;
            listViewBackFrame.AddChidren(btnRound);
            //明细列表的桌布,白色背景(覆盖弧度的圆的半边)
            this.detailBackFrame = new FrameLayout();
            detailBackFrame.Y = btnRound.Bottom - btnRound.Height / 2;
            detailBackFrame.Height = realDetailHeight;
            detailBackFrame.BackgroundColor = UserCenterColor.Current.White;
            listViewBackFrame.AddChidren(detailBackFrame);
        }
 
        /// <summary>
        /// 添加子控件
        /// </summary>
        /// <param name="view"></param>
        public override void AddChidren(View view)
        {
            if (detailBackFrame != null)
            {
                var tempView = detailBackFrame.GetChildren(detailBackFrame.ChildrenCount - 1);
                if (tempView != null)
                {
                    view.Y = tempView.Bottom;
                }
                detailBackFrame.AddChidren(view);
            }
        }
    }
}