|
using System;
|
|
namespace Shared
|
{
|
/// <summary>
|
/// Button 按键
|
/// </summary>
|
public class ViewGroup : View
|
{
|
/// <summary>
|
/// 真正的容器
|
/// </summary>
|
internal Android.Views.ViewGroup realViewGroup;
|
|
/// <summary>
|
/// 当前控件
|
/// </summary>
|
/// <value>The android frame layout.</value>
|
internal Android.Views.ViewGroup viewGroup
|
{
|
get
|
{
|
return AndroidView as Android.Views.ViewGroup;
|
}
|
set
|
{
|
AndroidView = value;
|
}
|
}
|
|
/// <summary>
|
/// 增加子控件
|
/// </summary>
|
/// <param name="view">View.</param>
|
public virtual void AddChidren(View view)
|
{
|
view.Parent = this;
|
viewList.Add(view);
|
if (GetType () == typeof (VerticalScrolViewLayout)) {
|
//这个是为了填充的
|
if (0<realViewGroup.ChildCount&&realViewGroup.GetChildAt (realViewGroup.ChildCount - 1).Tag != null&&realViewGroup.GetChildAt (realViewGroup.ChildCount - 1).Tag.ToString()=="填充") {
|
realViewGroup.RemoveViewAt (realViewGroup.ChildCount - 1);
|
}
|
}
|
if(view.AndroidView.Parent!=null){
|
(view.AndroidView.Parent as Android.Views.ViewGroup)?.RemoveView(view.AndroidView);
|
}
|
realViewGroup.AddView(view.AndroidView);
|
if (!IsCanRefresh)
|
{
|
return;
|
}
|
view.Refresh();
|
|
if (view is GestureLockView) {
|
new System.Threading.Thread(() =>
|
{
|
System.Threading.Thread.Sleep(100);
|
Shared.Application.RunOnMainThread(() =>
|
{
|
(view as GestureLockView).Height = view.Height+1;
|
(view as GestureLockView).Height = view.Height - 1;
|
});
|
}).Start();
|
}
|
|
//如果父控件是这种,就在最后补上一个控件
|
if (GetType () == typeof (VerticalScrolViewLayout)) {
|
int tempHeight = -10;
|
foreach (var temp in viewList) {
|
tempHeight += temp.Height;
|
}
|
realViewGroup.AddView (new Android.Widget.LinearLayout (Application.Activity) { Tag = "填充" }, new Android.Views.ViewGroup.LayoutParams (Android.Views.ViewGroup.LayoutParams.MatchParent, tempHeight < realViewGroup.LayoutParameters.Height ? realViewGroup.LayoutParameters.Height - tempHeight:0));
|
}
|
|
addParentToAllSubViews(view);
|
|
if (view is ViewGroup)
|
{
|
var tempViewGroup = (ViewGroup)view;
|
for (int i = 0; i < tempViewGroup.ChildrenCount; i++)
|
{
|
tempViewGroup.GetChildren(i).Refresh();
|
}
|
}
|
}
|
|
internal void addParentToAllSubViews(View view)
|
{
|
if (view is ViewGroup)
|
{
|
var viewgroup = view as ViewGroup;
|
for (int i = 0; i < viewgroup.viewList.Count; i++)
|
{
|
var _view = viewgroup.viewList[i];
|
if (_view == null) continue;
|
_view.Parent = viewgroup;
|
|
addParentToAllSubViews(_view);//递归,将子控件所包含的控件也一并移除;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 控件数量
|
/// </summary>
|
/// <value>The children count.</value>
|
public int ChildrenCount { get { return viewList.Count; } }
|
|
/// <summary>
|
/// 控件列表
|
/// </summary>
|
internal System.Collections.Generic.List<View> viewList = new System.Collections.Generic.List<View>();
|
|
|
string backgroundImagePath;
|
/// <summary>
|
/// 背景图片
|
/// </summary>
|
/// <value>The background image path.</value>
|
public virtual string BackgroundImagePath
|
{
|
get
|
{
|
return backgroundImagePath;
|
}
|
set
|
{
|
backgroundImagePath = value;
|
if (!IsCanRefresh || null == backgroundImagePath || Radius != 0)
|
{
|
return;
|
}
|
if (Background(backgroundImagePath))
|
{
|
|
}
|
}
|
}
|
|
/// <summary>
|
/// 刷新界面
|
/// </summary>
|
public override void Refresh()
|
{
|
base.Refresh();
|
BackgroundImagePath = backgroundImagePath;
|
}
|
|
/// <summary>
|
/// 移除控件
|
/// </summary>
|
/// <param name="view">View.</param>
|
internal virtual void Remove(View view)
|
{
|
if (view == null)
|
{
|
return;
|
}
|
|
viewList.Remove(view);
|
realViewGroup.RemoveView(view.AndroidView);
|
view.Parent = null;
|
}
|
|
internal virtual void removeChildParent()
|
{
|
for (int i = 0; i < viewList.Count; i++)
|
{
|
var view = viewList[i];
|
if (view == null) continue;
|
if (view is ViewGroup)
|
{
|
(view as ViewGroup).removeChildParent();
|
}
|
view.Parent = null;
|
//lock (dimageCached)
|
//{
|
// foreach (var keyValue in dimageCached)
|
// {
|
// if (keyValue.Key.StartsWith(view.GetHashCode() + "_", StringComparison.Ordinal))
|
// {
|
// dimageCached.Remove(keyValue.Key);
|
// keyValue.Value.Dispose();
|
// break;
|
// }
|
// }
|
//}
|
}
|
}
|
|
public override void RemoveFromParent()
|
{
|
removeChildParent();
|
base.RemoveFromParent();
|
}
|
|
|
|
/// <summary>
|
/// 清空所有的控件
|
/// </summary>
|
public virtual void RemoveAll()
|
{
|
while (0 < viewList.Count)
|
{
|
//Remove(GetChildren(0));
|
GetChildren(0)?.RemoveFromParent();
|
}
|
}
|
|
/// <summary>
|
/// 移除指定索引对象
|
/// </summary>
|
/// <param name="index">Index.</param>
|
public virtual void RemoveAt(int index)
|
{
|
//Remove(GetChildren(index));
|
GetChildren(index)?.RemoveFromParent();
|
}
|
|
/// <summary>
|
/// 获取指定索引对象
|
/// </summary>
|
/// <returns>The children.</returns>
|
/// <param name="index">Index.</param>
|
public View GetChildren(int index)
|
{
|
if (viewList.Count - 1 < index || index < 0)
|
{
|
return null;
|
}
|
return viewList[index];
|
}
|
|
/// <summary>
|
/// 根据类型移除控件
|
/// </summary>
|
/// <param name="type">Type.</param>
|
public void RemoveViewByType(System.Type type){
|
for (int i = 0; i < viewList.Count;i++)
|
{
|
if(viewList[i].GetType()==type)
|
{
|
viewList[i].RemoveFromParent();
|
i--;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 根据Tag移除控件
|
/// </summary>
|
/// <param name="type">Type.</param>
|
public void RemoveViewByTag(object tag)
|
{
|
for (int i = 0; i < viewList.Count; i++)
|
{
|
if (viewList[i].Tag == tag)
|
{
|
viewList[i].RemoveFromParent();
|
i--;
|
}
|
}
|
}
|
}
|
}
|