Xamarin Forms CollectionView Custom Layout Design

前端 未结 1 1256
青春惊慌失措
青春惊慌失措 2021-01-27 15:53

In the app that I\'m designing, I use collectionview to show loads of images. And this is my current design.

And this is the design I want. where the images that are sho

相关标签:
1条回答
  • 2021-01-27 16:44

    Unfortunately,CollectionView in Forms still doesn't support such a layout until now .However, we could use Custom Renderer as a workaround in Android.

    public class MyCollectionViewRenderer: CollectionViewRenderer
    {
        public MyCollectionViewRenderer(Context context) : base(context)
        {
    
        }
    
        protected override void OnElementChanged(ElementChangedEventArgs<ItemsView> elementChangedEvent)
        {
            base.OnElementChanged(elementChangedEvent);
    
            if(elementChangedEvent.NewElement!=null)
            {
                this.SetLayoutManager(new StaggeredGridLayoutManager(2, 1));
            }
    
        }
    }
    

    In iOS , because the UICollectionView in native iOS doesn't have such a property or API , so we need to implement it manually (re-calculate the size of each item and set the offset) . Which you could refer https://developer.apple.com/documentation/uikit/uicollectionview/customizing_collection_view_layouts?language=objc . And I will post the feature request as soon as possible .

    0 讨论(0)
提交回复
热议问题