using System;
|
using System.Collections.Generic;
|
using System.Text;
|
|
namespace Shared.Phone.UserCenter
|
{
|
/// <summary>
|
/// 做成一个上下可以滑动的列表控件(它会调整高度,无桌布)
|
/// </summary>
|
public class VerticalListControl : VerticalScrolViewLayout
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 行之间的间距
|
/// </summary>
|
public int rowSpace = 0;
|
/// <summary>
|
/// 最大高度
|
/// </summary>
|
private int maxHeight = -1;
|
/// <summary>
|
/// 一个没什么用的东西
|
/// </summary>
|
private FrameLayout frameBackTemp = null;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 做成一个上下可以滑动的列表控件(它会调整高度,无桌布)
|
/// </summary>
|
/// <param name="i_rowSpace">行之间的间距(这个值是与行控件绑定一起使用的)</param>
|
public VerticalListControl(int i_rowSpace = 0)
|
{
|
rowSpace = Application.GetRealHeight(i_rowSpace);
|
}
|
|
#endregion
|
|
#region ■ 添加子控件_________________________
|
|
/// <summary>
|
/// 添加子控件(FrameRowControl,RowLayoutControl会改变高度)
|
/// </summary>
|
/// <param name="view"></param>
|
public override void AddChidren(View view)
|
{
|
base.AddChidren(view);
|
if (view is FrameRowControl || view is RowLayoutControl)
|
{
|
if (rowSpace > 0)
|
{
|
view.Height += rowSpace;
|
}
|
}
|
if (maxHeight == -1)
|
{
|
maxHeight = this.Height;
|
}
|
}
|
#endregion
|
|
#region ■ 调整真实高度_______________________
|
|
/// <summary>
|
/// 还原高度
|
/// </summary>
|
public void RecoverHeight()
|
{
|
if (this.maxHeight != -1)
|
{
|
this.Height = this.maxHeight;
|
}
|
}
|
|
/// <summary>
|
/// 调整控件真实高度(只针对行控件都是相同高度的,高度只会减少,不会增加)
|
/// </summary>
|
/// <param name="bottomSpace">底部空白间距(真实值)</param>
|
/// <param name="addSpace">当真实高度超过原有高度时,是否添加空白</param>
|
public void AdjustRealHeight(int bottomSpace, bool addSpace = true)
|
{
|
int count = frameBackTemp == null ? this.ChildrenCount : this.ChildrenCount - 1;
|
if (count <= 0)
|
{
|
frameBackTemp?.RemoveFromParent();
|
frameBackTemp = null;
|
//还原为最大高度
|
this.Height = maxHeight;
|
return;
|
}
|
|
//调整列表控件的高度
|
var realHeight = count * this.GetChildren(0).Height + bottomSpace;
|
if (realHeight < this.Height)
|
{
|
frameBackTemp?.RemoveFromParent();
|
frameBackTemp = null;
|
//缩小控件高度
|
this.Height = realHeight;
|
}
|
else if (addSpace == true && bottomSpace > 0 && realHeight > this.maxHeight)
|
{
|
frameBackTemp?.RemoveFromParent();
|
|
frameBackTemp = new FrameLayout();
|
frameBackTemp.Height = bottomSpace;
|
this.AddChidren(frameBackTemp);
|
}
|
}
|
|
#endregion
|
}
|
}
|