0

I am trying to do a slideshow display of items and I have an issue where there is a mysterious padding added to the first cell(on the left side) and last cell(right side) as shown below and demonstrated by the black box

enter image description here

            DataSource datasource = new DataSource(Vcollection, PageControl, this);
            Vcollection.Source = datasource;

            doRefreshList = true;

            Vcollection.CollectionViewLayout = new UICollectionViewFlowLayout()
            {
                ItemSize = Vcollection.Frame.Size,
                HeaderReferenceSize = new CGSize(0, 0),
                SectionInset = UIEdgeInsets.Zero,
                ScrollDirection = UICollectionViewScrollDirection.Horizontal,

                MinimumInteritemSpacing = 0f, // minimum spacing between cells
                MinimumLineSpacing = 0f,
                SectionInsetReference = UICollectionViewFlowLayoutSectionInsetReference.ContentInset,

            };
            Vcollection.ContentInset = UIEdgeInsets.Zero;
            Vcollection.ScrollIndicatorInsets = UIEdgeInsets.Zero;
            Vcollection.ContentOffset = new CGPoint(0f, 0f);
            this.AutomaticallyAdjustsScrollViewInsets = false;

This is my code where I tried to rectify the issue, but to no avail. How can I remove this padding?

------------------EDIT --------------------- Replacing the last 4 lines with

VehicleCollectionView.ContentInset = new UIEdgeInsets(0, -20, 0, 0);
            VehicleCollectionView.ContentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.Never;

Works, however pagination is still off. attempting to scroll through the collectionview shows huge offsets as shown below where pagination is stuck between 2 items

enter image description here

slushpuppy
  • 107
  • 1
  • 8
  • Try to set ContentInset of CollectionView and set AutomaticallyAdjustsScrollViewInsets to false ,refer https://stackoverflow.com/a/23786370/8187800. – ColeX Sep 13 '19 at 12:13
  • Works for the first page, scrolling through rest of the pages shows weird offsets – slushpuppy Sep 13 '19 at 17:20
  • What weird offsets ? Could you post a basic project for us to test ? – ColeX Sep 27 '19 at 09:02

1 Answers1

0

In your ViewDidLoad() method you can try two write this code

collectionView.ContentInset = new UIEdgeInsets (10, 10, 10, 10);
//collectionView.SectionInset = new UIEdgeInsets (20, 20, 20, 20)
R15
  • 13,982
  • 14
  • 97
  • 173