| | |
| | | /// </summary> |
| | | private int mRowNumber; |
| | | |
| | | private List<int> mList; |
| | | private List<string> mList; |
| | | |
| | | public Action<int> selectAction = null; |
| | | public Action<string> selectAction = null; |
| | | /// <summary> |
| | | /// 当前选择的索引(内部使用) |
| | | /// </summary> |
| | | private int CurrnetSelectIndex = -1; |
| | | |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | |
| | | /// <param name="height">容器高度</param> |
| | | ///<param name="rowNumber">一行几个元素</param> |
| | | ///<param name="rowNumber">圆角值</param> |
| | | public CornerFramLayout(int width, int height, int rowNumber,int radius=0) |
| | | public CornerFramLayout(int width, int height, int rowNumber = 0, int radius = 0) |
| | | { |
| | | this.BackgroundColor = MusicColor.WhiteColor; |
| | | this.Width = Application.GetRealWidth(width); |
| | | this.Height = Application.GetRealHeight(height); |
| | | this.Radius = (uint)Application.GetRealHeight(radius); |
| | | this.mRowNumber = rowNumber; |
| | | |
| | | |
| | | } |
| | | /// <summary> |
| | |
| | | /// 设置列表数据(请在初始化完成之前调用) |
| | | /// </summary> |
| | | /// <param name="list"></param> |
| | | public void SetList(List<int> list) |
| | | public void SetList(List<string> list) |
| | | { |
| | | if (list == null) |
| | | { |
| | | list = new List<int>(); |
| | | list = new List<string>(); |
| | | } |
| | | this.mList = list; |
| | | } |
| | |
| | | /// <summary> |
| | | /// 获取测试列表数据 |
| | | /// </summary> |
| | | public List<int> GetTestList(int count) |
| | | public List<string> GetTestList(int count) |
| | | { |
| | | var list = new List<int>(); |
| | | var list = new List<string>(); |
| | | for (int i = 1; i <= count; i++) |
| | | { |
| | | list.Add(i); |
| | | if (i % 2 == 0) |
| | | { |
| | | list.Add("你好傻哦!"); |
| | | } |
| | | else |
| | | { |
| | | list.Add("真的是这样的吗?"); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 动态加载按键界面 |
| | | /// (注意:mRowNumber!=0) |
| | | /// </summary> |
| | | public void LoadButtonPage() |
| | | { |
| | |
| | | int xCount = 0; |
| | | for (int i = 1; i <= this.mList.Count; i++) |
| | | { |
| | | var d = this.mList[i - 1]; |
| | | ButtonFramLayout buttonFram = new ButtonFramLayout(); |
| | | this.AddChidren(buttonFram); |
| | | buttonFram.Tag = i - 1; |
| | | buttonFram.Tag = d; |
| | | buttonFram.Y = Application.GetRealHeight(this.topMargin) + Application.GetRealHeight(ButtonFramLayout.heightFrameLayout * line); |
| | | buttonFram.X = Application.GetRealWidth(this.leftMargin) + Application.GetRealWidth(ButtonFramLayout.widthFrameLayout * xCount); |
| | | buttonFram.AddImageView(); |
| | |
| | | { |
| | | buttonFram.AddBottomLine(); |
| | | } |
| | | buttonFram.GetNameButton().Text = i.ToString(); |
| | | buttonFram.GetNameButton().Text = d; |
| | | |
| | | xCount++; |
| | | if (i % this.mRowNumber == 0) |
| | |
| | | } |
| | | buttonFram.SetClickListener((fl, btnIcon, btnName) => |
| | | { |
| | | selectAction?.Invoke((int)buttonFram.Tag); |
| | | if (buttonFram.Tag != null) |
| | | { |
| | | selectAction?.Invoke(buttonFram.Tag.ToString()); |
| | | } |
| | | }); |
| | | |
| | | //if (CurrnetSelectIndex != -1 && CurrnetSelectIndex == i) |
| | |
| | | //} |
| | | |
| | | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 动态加载按键界面 |
| | | /// </summary> |
| | | /// <param name="list">索引列表,表示某一条宽度加宽</param> |
| | | public void LoadButtonPage(List<int> list) |
| | | { |
| | | |
| | | int currnetheightValue = 0; |
| | | int currnetWidthValue = 0; |
| | | //获取相对一个纬度值 |
| | | int heightDimensionValue = this.Height - Application.GetRealHeight(this.topMargin) - Application.GetRealHeight(this.bottomMargin) - Application.GetRealHeight(ButtonFramLayout.heightFrameLayout / 2); |
| | | int widthDimensionValue = this.Width - Application.GetRealWidth(this.leftMargin) - Application.GetRealWidth(this.rightMargin) - Application.GetRealHeight(ButtonFramLayout.widthFrameLayout / 2); |
| | | for (int i = 1; i <= this.mList.Count; i++) |
| | | { |
| | | var d = this.mList[i - 1]; |
| | | ButtonFramLayout buttonFram = null; |
| | | if (list.Contains(i)) |
| | | { |
| | | buttonFram = new ButtonFramLayout(ButtonFramLayout.widthFrameLayout * 2); |
| | | buttonFram.Y = Application.GetRealHeight(this.topMargin) + Application.GetRealHeight(currnetheightValue); |
| | | buttonFram.X = Application.GetRealWidth(this.leftMargin) + Application.GetRealWidth(currnetWidthValue); |
| | | currnetWidthValue += ButtonFramLayout.widthFrameLayout * 2; |
| | | } |
| | | else |
| | | { |
| | | buttonFram = new ButtonFramLayout(); |
| | | buttonFram.Y = Application.GetRealHeight(this.topMargin) + Application.GetRealHeight(currnetheightValue); |
| | | buttonFram.X = Application.GetRealWidth(this.leftMargin) + Application.GetRealWidth(currnetWidthValue); |
| | | currnetWidthValue += ButtonFramLayout.widthFrameLayout; |
| | | |
| | | } |
| | | |
| | | this.AddChidren(buttonFram); |
| | | buttonFram.AddImageView(); |
| | | buttonFram.AddNameView(); |
| | | buttonFram.Tag = d;//标记数据 |
| | | buttonFram.GetNameButton().Text = d.ToString(); |
| | | if (widthDimensionValue > Application.GetRealWidth(currnetWidthValue)) |
| | | { |
| | | //加右线 |
| | | buttonFram.AddRightLine(); |
| | | } |
| | | |
| | | if (heightDimensionValue > buttonFram.Bottom) |
| | | { |
| | | //加底线 |
| | | buttonFram.AddBottomLine(); |
| | | } |
| | | |
| | | if (widthDimensionValue < Application.GetRealWidth(currnetWidthValue)) |
| | | { |
| | | currnetheightValue += ButtonFramLayout.heightFrameLayout; |
| | | currnetWidthValue = 0; |
| | | } |
| | | |
| | | buttonFram.SetClickListener((fl, btnIcon, btnName) => |
| | | { |
| | | if (buttonFram.Tag != null) |
| | | { |
| | | selectAction?.Invoke(buttonFram.Tag.ToString()); |
| | | } |
| | | }); |
| | | |
| | | //if (CurrnetSelectIndex != -1 && CurrnetSelectIndex == i) |
| | | //{ |
| | | // selectAction?.Invoke((int)buttonFram.Tag); |
| | | //} |
| | | } |
| | | } |
| | | |
| | |
| | | int xCount = 0; |
| | | for (int i = 1; i <= this.mList.Count; i++) |
| | | { |
| | | var d = this.mList[i - 1]; |
| | | ImageFramlayout imageFram = new ImageFramlayout(); |
| | | imageFram.AddView(this); |
| | | //this.AddChidren(imageFram); |
| | | imageFram.Tag = i - 1; |
| | | imageFram.Tag = d; |
| | | imageFram.Y = Application.GetRealHeight(this.topMargin)+ Application.GetRealHeight((ImageFramlayout.heightFrameLayout + 20) * line); |
| | | imageFram.X = Application.GetRealWidth((ImageFramlayout.widthFrameLayout + 8) * xCount); |
| | | //imageFram.AddImageView(); |
| | | //imageFram.AddScoreButton(); |
| | | //imageFram.AddNameButton(); |
| | | imageFram.btnName.Text = i.ToString(); |
| | | imageFram.btnName.Text = d; |
| | | |
| | | xCount++; |
| | | if (i % this.mRowNumber == 0) |
| | |
| | | } |
| | | imageFram.SetClickListener((fl) => |
| | | { |
| | | selectAction?.Invoke((int)imageFram.Tag); |
| | | if (imageFram.Tag != null) |
| | | { |
| | | selectAction?.Invoke(imageFram.Tag.ToString()); |
| | | } |
| | | }); |
| | | |
| | | //if (CurrnetSelectIndex != -1 && CurrnetSelectIndex == i) |
| | |
| | | /// <summary> |
| | | /// 最后一行 |
| | | /// </summary> |
| | | /// <param name="value"></param> |
| | | /// <param name="index">当前索引值</param> |
| | | /// <returns></returns> |
| | | private bool IsLastColumn(int value) |
| | | private bool IsLastColumn(int index) |
| | | { |
| | | int lineCount = this.mList.Count / this.mRowNumber; |
| | | int lineCount = this.mList.Count / this.mRowNumber;//得出行数 |
| | | int number = this.mList.Count % this.mRowNumber; |
| | | if (number != 0) |
| | | { |
| | | if (value > lineCount * this.mRowNumber) |
| | | if (index > lineCount * this.mRowNumber) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (value > lineCount-- * this.mRowNumber) |
| | | int value = --lineCount * this.mRowNumber; |
| | | if (index > value) |
| | | { |
| | | return true; |
| | | } |
| | |
| | | }; |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 重新计算button宽度 |
| | | /// </summary> |
| | | /// <param name="button">控件</param> |
| | | /// <param name="widthMax">宽度最大最</param> |
| | | /// <param name="padding">内边距</param> |
| | | private void AdjustRealWidth(Button button, int widthMax = 0, int padding = 0) |
| | | { |
| | | if (button == null) |
| | | { |
| | | return; |
| | | } |
| | | int width; |
| | | if (widthMax == 0) |
| | | { |
| | | //内边距 |
| | | width = button.GetTextWidth() + Application.GetRealWidth(padding * 2); |
| | | } |
| | | else |
| | | { |
| | | if (button.GetTextWidth() > Application.GetRealWidth(widthMax)) |
| | | { |
| | | |
| | | button.TextSize = 10;//控件高度不变,改变字体大小,准备换行; |
| | | width = Application.GetRealWidth(widthMax); |
| | | } |
| | | else |
| | | { |
| | | width = button.GetTextWidth(); |
| | | } |
| | | |
| | | } |
| | | |
| | | button.Width = width; |
| | | } |
| | | } |
| | | } |