}
}
- var makeBline = true;
+ var cellIsBeingReused = false;
var layout = convertView as ConditionalFocusLayout;
if (layout != null)
{
- makeBline = false;
+ cellIsBeingReused = true;
convertView = layout.GetChildAt(0);
}
else
Performance.Start("AddView");
- if (!makeBline)
+ if (cellIsBeingReused)
{
if (convertView != view)
{
Performance.Stop("AddView");
- AView bline;
- if (makeBline)
- {
- bline = new AView(_context) { LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 1) };
-
- layout.AddView(bline);
- }
- else
- bline = layout.GetChildAt(1);
-
bool isHeader = cell.GetIsGroupHeader<ItemsView<Cell>, Cell>();
- Color separatorColor = _listView.SeparatorColor;
-
- if (nextCellIsHeader || _listView.SeparatorVisibility == SeparatorVisibility.None)
- bline.SetBackgroundColor(global::Android.Graphics.Color.Transparent);
- else if (isHeader || !separatorColor.IsDefault)
- bline.SetBackgroundColor(separatorColor.ToAndroid(Color.Accent));
- else
- {
- if (s_dividerHorizontalDarkId == int.MinValue)
- {
- using (var value = new TypedValue())
- {
- int id = global::Android.Resource.Drawable.DividerHorizontalDark;
- if (_context.Theme.ResolveAttribute(global::Android.Resource.Attribute.ListDivider, value, true))
- id = value.ResourceId;
- else if (_context.Theme.ResolveAttribute(global::Android.Resource.Attribute.Divider, value, true))
- id = value.ResourceId;
+ AView bline;
- s_dividerHorizontalDarkId = id;
- }
- }
+ UpdateSeparatorVisibility(cell, cellIsBeingReused, isHeader, nextCellIsHeader, layout, out bline);
- bline.SetBackgroundResource(s_dividerHorizontalDarkId);
- }
+ UpdateSeparatorColor(isHeader, bline);
if ((bool)cell.GetValue(IsSelectedProperty))
Select(position, layout);
Select(position, view);
}
+ void UpdateSeparatorVisibility(Cell cell, bool cellIsBeingReused, bool isHeader, bool nextCellIsHeader, ConditionalFocusLayout layout, out AView bline)
+ {
+ bline = null;
+ if (cellIsBeingReused)
+ return;
+ var makeBline = _listView.SeparatorVisibility == SeparatorVisibility.Default || isHeader && !nextCellIsHeader;
+ if (makeBline)
+ {
+ bline = new AView(_context) { LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 1) };
+ layout.AddView(bline);
+ }
+ else if (layout.ChildCount > 1)
+ {
+ layout.RemoveViewAt(1);
+ }
+ }
+
+
+ void UpdateSeparatorColor(bool isHeader, AView bline)
+ {
+ if (bline == null)
+ return;
+
+ Color separatorColor = _listView.SeparatorColor;
+
+ if (isHeader || !separatorColor.IsDefault)
+ bline.SetBackgroundColor(separatorColor.ToAndroid(Color.Accent));
+ else
+ {
+ if (s_dividerHorizontalDarkId == int.MinValue)
+ {
+ using (var value = new TypedValue())
+ {
+ int id = global::Android.Resource.Drawable.DividerHorizontalDark;
+ if (_context.Theme.ResolveAttribute(global::Android.Resource.Attribute.ListDivider, value, true))
+ id = value.ResourceId;
+ else if (_context.Theme.ResolveAttribute(global::Android.Resource.Attribute.Divider, value, true))
+ id = value.ResourceId;
+
+ s_dividerHorizontalDarkId = id;
+ }
+ }
+
+ bline.SetBackgroundResource(s_dividerHorizontalDarkId);
+ }
+ }
+
enum CellType
{
Row,
get { return ViewCell; }
}
+ internal bool SupressSeparator { get; set; }
+
public override void LayoutSubviews()
{
//This sets the content views frame.
base.LayoutSubviews();
+ if (SupressSeparator)
+ {
+ var oldFrame = Frame;
+ ContentView.Bounds = Frame = new RectangleF(oldFrame.Location, new SizeF(oldFrame.Width, oldFrame.Height + 0.5f));
+ }
+
var contentFrame = ContentView.Frame;
var view = ViewCell.View;
var height = size.Height > 0 ? size.Height : double.PositiveInfinity;
var result = renderer.Element.Measure(width, height);
- // make sure to add in the separator
- return new SizeF(size.Width, (float)result.Request.Height + 1f / UIScreen.MainScreen.Scale);
+ // make sure to add in the separator if needed
+ var finalheight = ((float)result.Request.Height + (SupressSeparator ? 0f : 1f)) / UIScreen.MainScreen.Scale;
+ return new SizeF(size.Width, finalheight);
}
protected override void Dispose(bool disposing)