using System;
using Shared;
using HDL_ON.UI.Music;
using System.Collections.Generic;
namespace HDL_ON.UI.UI2.FuntionControlView.Aks.CommonView
{
///
/// 水平滑动容器
///
public class HorizontalFramLayout : HorizontalScrolViewLayout
{
///
///
///
/// 容器宽度
/// 容器高度
public HorizontalFramLayout(int width, int height)
{
this.Height = Application.GetRealHeight(height);
this.Width = Application.GetRealWidth(width);
}
private List mList = new List();
///
/// 选择事件
///
public Action SelectTypeEvent = null;
///
/// 当前选择的索引(内部使用)
///
private int CurrnetSelectIndex = -1;
///
/// 初始化控件
///
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);
}
}
}
///
/// 设置初始选择(请在初始化完成之前调用)
///
/// 从列表0开始计算第一个元素,设置超过列表最大(new List().count-1)值视为无效
public void SetIndex(int index = -1)
{
if (index == -1) { return; }
this.CurrnetSelectIndex = index;
}
///
/// 设置列表数据(请在初始化完成之前调用)
///
public void SetList(List list)
{
if (list == null)
{
this.mList = new List();
}
this.mList = list;
}
///
/// 测试数据
///
public List GetTestData
{
get
{
return new List { "4245725454", "2", "类型", "中国电影", "全部类型", "类型发送地哦哦哦", "中国电影感觉对酒当歌", "全部类型", };
}
}
///
/// 控件摧毁
///
public override void RemoveFromParent()
{
this.SelectTypeEvent = null;
base.RemoveFromParent();
}
}
}