Пример #1
0
        void UpdateSeparatorVisibility(Cell cell, bool cellIsBeingReused, bool isHeader, bool nextCellIsHeader, bool isSeparatorVisible, ConditionalFocusLayout layout, out AView bline)
        {
            bline = null;
            if (cellIsBeingReused && layout.ChildCount > 1)
            {
                layout.RemoveViewAt(1);
            }
            var makeBline = isSeparatorVisible || isHeader && isSeparatorVisible && !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);
            }
        }
Пример #2
0
        public override AView GetView(int position, AView convertView, ViewGroup parent)
        {
            bool isHeader, nextIsHeader;
            Cell item = GetCellForPosition(position, out isHeader, out nextIsHeader);

            if (item == null)
            {
                return(new AView(Context));
            }

            var makeBline = true;
            var layout    = convertView as ConditionalFocusLayout;

            if (layout != null)
            {
                makeBline   = false;
                convertView = layout.GetChildAt(0);
            }
            else
            {
                layout = new ConditionalFocusLayout(Context)
                {
                    Orientation = Orientation.Vertical
                }
            };

            AView aview = CellFactory.GetCell(item, convertView, parent, Context, _view);

            if (!makeBline)
            {
                if (convertView != aview)
                {
                    layout.RemoveViewAt(0);
                    layout.AddView(aview, 0);
                }
            }
            else
            {
                layout.AddView(aview, 0);
            }

            AView bline;

            if (makeBline)
            {
                bline = new AView(Context)
                {
                    LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 1)
                };

                layout.AddView(bline);
            }
            else
            {
                bline = layout.GetChildAt(1);
            }

            if (isHeader)
            {
                bline.SetBackgroundColor(Color.Accent.ToAndroid());
            }
            else if (nextIsHeader)
            {
                bline.SetBackgroundColor(global::Android.Graphics.Color.Transparent);
            }
            else
            {
                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;
                    }

                    bline.SetBackgroundResource(id);
                }
            }

            layout.ApplyTouchListenersToSpecialCells(item);

            if (_restoreFocus == item)
            {
                if (!aview.HasFocus)
                {
                    aview.RequestFocus();
                }

                _restoreFocus = null;
            }
            else if (aview.HasFocus)
            {
                aview.ClearFocus();
            }

            return(layout);
        }