Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Fixed grouped list header height

$
0
0

Hey all,

I would like to make a ListView with grouping enabled, so far, everything is good.
But I need to layout my own header with fixed height, and there is where the problem comes:
The header is drawn well, but it hides the first cell from the corresponding group. (My header is bigger than the default size)

My code looks like this:

GroupHeaderTemplate = new DataTemplate(() =>
                {
                    var relativeLayout = new RelativeLayout
                    {
                        HeightRequest = Normalize(headerHeight),
                        VerticalOptions = LayoutOptions.Start,
                        Padding = 0
                    };

                    var bgImage = new Image
                    {
                        Source = new FileImageSource { File = LocalDataManager.CombineLibraryPath("bgImage.png") },
                        VerticalOptions = LayoutOptions.FillAndExpand,
                        Aspect = Aspect.AspectFill
                    };

                    relativeLayout.Children.Add(bgImage,
                        Constraint.Constant(0),
                        Constraint.Constant(0),
                        Constraint.RelativeToParent((parent) => parent.Width),
                        Constraint.RelativeToParent((parent) => parent.Height));

                    var nameLabel = new Label();

                    nameLabel.SetBinding(Label.TextProperty, "Label");
                    nameLabel.SetValue(Label.TextColorProperty, ThemeManager.GroupedListHeaderTextColor.ToColor());
                    nameLabel.SetValue(Label.XAlignProperty, TextAlignment.Start);
                    nameLabel.SetValue(Label.YAlignProperty, TextAlignment.Center);

                    relativeLayout.Children.Add(nameLabel,
                        Constraint.Constant(0),
                        Constraint.Constant(0),
                        Constraint.RelativeToParent((parent) => parent.Width),
                        Constraint.RelativeToParent((parent) => parent.Height));

                    return new ViewCell
                    {
                        Height = Normalize(headerHeight),
                        View = new StackLayout
                        {
                            HeightRequest = Normalize(headerHeight),
                            VerticalOptions = LayoutOptions.StartAndExpand,
                            Children = { relativeLayout }
                        }
                    };
                })

Did I do anything wrong, or just the default height is supported?

Attached a file too.

Thanks in advance!


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>