namespace Shared { /// /// Button 按键 /// public class ViewGroup : View { /// /// 真正的容器 /// internal Android.Views.ViewGroup realViewGroup; /// /// 当前控件 /// /// The android frame layout. internal Android.Views.ViewGroup viewGroup { get { return AndroidView as Android.Views.ViewGroup; } set { AndroidView = value; } } /// /// 增加子控件 /// /// View. public virtual void AddChidren(View view) { view.Parent = this; viewList.Add(view); if (GetType () == typeof (VerticalScrolViewLayout)) { //这个是为了填充的 if (0 /// 控件数量 /// /// The children count. public int ChildrenCount { get { return viewList.Count; } } /// /// 控件列表 /// internal System.Collections.Generic.List viewList = new System.Collections.Generic.List(); string backgroundImagePath; /// /// 背景图片 /// /// The background image path. public virtual string BackgroundImagePath { get { return backgroundImagePath; } set { backgroundImagePath = value; if (!IsCanRefresh || null == backgroundImagePath || Radius != 0) { return; } if (Background(backgroundImagePath)) { } } } /// /// 刷新界面 /// public override void Refresh() { base.Refresh(); BackgroundImagePath = backgroundImagePath; } /// /// 移除控件 /// /// View. public virtual void Remove(View view) { if (view == null) { return; } viewList.Remove(view); realViewGroup.RemoveView(view.AndroidView); view.Parent = null; } /// /// 清空所有的控件 /// public virtual void RemoveAll() { while (0 < viewList.Count) { //Remove(GetChildren(0)); GetChildren(0)?.RemoveFromParent(); } } /// /// 移除指定索引对象 /// /// Index. public virtual void RemoveAt(int index) { //Remove(GetChildren(index)); GetChildren(index)?.RemoveFromParent(); } /// /// 获取指定索引对象 /// /// The children. /// Index. public View GetChildren(int index) { if (viewList.Count - 1 < index || index < 0) { return null; } return viewList[index]; } /// /// 根据类型移除控件 /// /// Type. public void RemoveViewByType(System.Type type){ for (int i = 0; i < viewList.Count;i++) { if(viewList[i].GetType()==type) { viewList[i].RemoveFromParent(); i--; } } } /// /// 根据Tag移除控件 /// /// Type. public void RemoveViewByTag(object tag) { for (int i = 0; i < viewList.Count; i++) { if (viewList[i].Tag == tag) { viewList[i].RemoveFromParent(); i--; } } } } }