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
|
{
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="width">容器宽度</param>
|
/// <param name="height">容器高度</param>
|
public HorizontalFramLayout(int width, int height)
|
{
|
this.Height = Application.GetRealHeight(height);
|
this.Width = Application.GetRealWidth(width);
|
}
|
|
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();
|
}
|
|
}
|
}
|