wjc
2023-08-02 a0ff1e2375ea0ad8ea127341e04799be8123bd54
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
using System;
using Shared;
using HDL_ON.UI.Music;
using System.Collections.Generic;
 
namespace HDL_ON.UI.UI2.FuntionControlView.Aks.CommonView
{
    /// <summary>
    /// 水平滑动容器
    /// </summary>
    public class HorizontalFramLayout : HorizontalScrolViewLayout
    {
        public HorizontalFramLayout()
        {
            this.Height = Application.GetRealHeight(28);
        }
 
        private List<string> mList = new List<string>();
        /// <summary>
        /// 选择事件
        /// </summary>
        public Action<int> SelectTypeEvent = null;
 
        /// <summary>
        /// 当前选择的索引(内部使用)
        /// </summary>
        private int CurrnetSelectIndex = -1;
 
 
        /// <summary>
        /// 初始化控件
        /// </summary>
        public void InitControl()
        {
            if (this.mList == null || this.mList.Count == 0)
            {
                return;
            }
            Button btnSelected = new Button();
            for (int i = 0; i < this.mList.Count; i++)
            {
                Button button = new Button
                {
                    Height = Application.GetRealHeight(28),
                    Width = Application.GetRealWidth(20),
                    SelectedBackgroundColor = MusicColor.ViewColor,
                    BackgroundColor = 0x00000000,
                    Text = mList[i],
                    TextSize = TextSize.Text14,
                    TextColor = MusicColor.TextColor,
                    SelectedTextColor = MusicColor.MusicTxet14SelectedColor,
                    TextAlignment = TextAlignment.Center,
                    Padding = new Padding(4, 4, 4, 4),
                    Radius = (uint)Application.GetRealHeight(4),
                    Tag = i,
                };
 
                //重新计算组件宽度
                button.Width = button.GetTextWidth() + Application.GetRealWidth(4 + 4);
                this.AddChidren(button);
                //间隔,弄个空的进去占位置
                Button btnSpacing = new Button
                {
                    Height = Application.GetRealHeight(28),
                    Width = Application.GetRealWidth(20),
                    BackgroundColor = 0x00000000,
                };
                this.AddChidren(btnSpacing);
                button.MouseDownEventHandler += (sen, e) =>
                {
                    btnSelected.IsSelected = false;
                    button.IsSelected = true;
                    btnSelected = button;
                    if (button.Tag == null)
                    {
                        return;
                    }
                    SelectTypeEvent?.Invoke((int)button.Tag);
 
                };
                if (CurrnetSelectIndex != -1 && CurrnetSelectIndex == i)
                {
                    btnSelected.IsSelected = false;
                    button.IsSelected = true;
                    btnSelected = button;
                    if (button.Tag == null)
                    {
                        return;
                    }
                    SelectTypeEvent?.Invoke((int)button.Tag);
                }
            }
 
 
 
        }
 
 
        /// <summary> 
        /// 设置初始选择(请在初始化完成之前调用)
        /// </summary>
        /// <param name="index">从列表0开始计算第一个元素,设置超过列表最大(new List().count-1)值视为无效</param>
        public void SetIndex(int index = -1)
        {
            if (index == -1) { return; }
            this.CurrnetSelectIndex = index;
 
        }
 
        /// <summary> 
        /// 设置列表数据(请在初始化完成之前调用)
        /// </summary>
        public void SetList(List<string> list)
        {
            if (list == null)
            {
                this.mList = new List<string>();
            }
            this.mList = list;
 
        }
        /// <summary> 
        /// 测试数据
        /// </summary>
        public List<string> GetTestData
        {
            get
            {
                return new List<string> { "4245725454", "2", "类型", "中国电影", "全部类型", "类型发送地哦哦哦", "中国电影感觉对酒当歌", "全部类型", };
            }
 
        }
 
 
        /// <summary>
        /// 控件摧毁
        /// </summary>
        public override void RemoveFromParent()
        {
            this.SelectTypeEvent = null;
            base.RemoveFromParent();
        }
 
    }
}