示例#1
0
        public void AddRows(List <Sample> sources)
        {
            int itemsInRow = 2;

            int width  = Context.Resources.DisplayMetrics.WidthPixels;
            int height = Context.Resources.DisplayMetrics.HeightPixels;

            if (width > height)
            {
                itemsInRow = 3;

                if (IsLargeTablet)
                {
                    itemsInRow = 4;
                }
            }
            else if (IsLargeTablet)
            {
                itemsInRow = 3;
            }

            int padding = width / 50;

            int x = padding;
            int y = padding;
            int w = (width - ((itemsInRow + 1) * padding)) / itemsInRow;
            int h = w;

            foreach (Sample source in sources)
            {
                GalleryRow row = new GalleryRow(Context, source);
                container.AddView(row);
                rows.Add(row);

                row.Frame = new CGRect(x, y, w, h);

                row.Click += (sender, e) => {
                    RowClick(sender, e);
                };

                if (x == ((w * (itemsInRow - 1)) + padding * itemsInRow))
                {
                    y += h + padding;
                    x  = padding;
                }
                else
                {
                    x += w + padding;
                }

                if (sources.IndexOf(source) == sources.Count - 1)
                {
                    (row.LayoutParameters as RelativeLayout.LayoutParams).BottomMargin = padding;
                }
            }
        }
示例#2
0
        public void AddRows(List <MapGallerySource> sources)
        {
            int itemsInRow = 2;

            int width  = Context.Resources.DisplayMetrics.WidthPixels;
            int height = Context.Resources.DisplayMetrics.HeightPixels;

            if (width > height)
            {
                itemsInRow = 3;

                if (IsLargeTablet)
                {
                    itemsInRow = 4;
                }
            }
            else if (IsLargeTablet)
            {
                itemsInRow = 3;
            }

            int padding = width / 50;

            int x = padding;
            int y = padding;
            int w = (width - ((itemsInRow + 1) * padding)) / itemsInRow;
            int h = w;

            foreach (MapGallerySource source in sources)
            {
                GalleryRow row = new GalleryRow(Context, source);
                container.AddView(row);
                rows.Add(row);

                var parameters = new RelativeLayout.LayoutParams(w, h);
                parameters.LeftMargin = x;
                parameters.TopMargin  = y;

                row.LayoutParameters = parameters;

                row.Click += (sender, e) => {
                    RowClick(sender, e);
                };

                if (x == ((w * (itemsInRow - 1)) + padding * itemsInRow))
                {
                    y += h + padding;
                    x  = padding;
                }
                else
                {
                    x += w + padding;
                }
            }
        }