-
Notifications
You must be signed in to change notification settings - Fork 1.9k
CollectionView height doesn't adapt after height of its content #6554
Comments
@luczha Can you attach a repro? Also, can you test your code with the latest pre-release? |
Below in yellow is a Collectionview with a DataTemplate with a Frame and a nested label, I dont see why this should be stretching that much space vertically. The orientation of the CollectionView is set to horizontal. The way I see it only need the CollectionView to fit the frame and nested label. If this is default behavour then it would be better if the CollectionView would simply fit the content without having to set the HeightRequest (which is my work around). |
+1 on this |
+1 |
1 similar comment
+1 |
+2 |
+1 |
1 similar comment
+1 |
Same problem here. it doesn't even show all entries. Tried it with BindableLayout and it worked as expected:
CollectionView does not work (vertically all items are displayed and height is also ok):
If you need a sample repo let me know. |
+1 |
@samhouts @adrianknight89 Hi ,all .Any update ? Or it would better if there is a workaround . We can implement it by using custom renderer in Android . However , in iOS there is no such a property or API . |
+1 |
Hi All, Any update? |
+1 |
1 similar comment
+1 |
+1 |
A simple solution is to calculate the height and set it with a MVVM auto-updating parameter. |
@eli191 do you have any small sample? :) |
@tscholze I am doing it through |
+1 |
2 similar comments
+1 |
+1 |
any update here? have similar issue |
This is not an issue. This is by design. So if you still want to autoheight a ScrollView, sum the height of each element and each separator, and set the HeightRequest of the CollectionView to this value. At runtime. |
There really should be a property that can be turned on for when this behaviour is desired. It gets really unwieldy setting the height manually with collections that can change as you will have to add all kinds of listeners in code for something that should imho be built into the component. |
@Tommigun1980 both iOS and Android uses optimized virtual lists which includes fast scrolling with acceleration. To be able to do that, they don't compute the height of each item as this would require a full layout of each item view, plus a binding of each item view with its datamodel (as you know, those virtual lists keep only about 10 views - they don't create a view for each item). Instead they suppose each item has a certain height (which you can give). This height is mainly used for displaying the scroll handle on the right while scrolling, and detect the end of the list is to stop scrolling smoothly. As Android does support dynamic height change of visible items, iOS does not. On iOS the correct way to do this is to remove/add the item again in a "transaction" so it can smoothly animate the change. But transactions are not available on out-of-the-box ObservableCollections on .NET ... even on .NET 5. And of course is not implemented in the backed Items container on iOS in Xamarin Forms. Well that i not exactly true. Xamarin Forms iOS does implement a fake transaction by buffering changes happening on the same thread. When the main thread is free, it applies the changes. |
When the measurement strategy is MeasureFirstItem I don't see why it couldn't be done, as it'd be analogous to a BindableLayout (with virtualisation support). It'd just be 'items * firstItemHeight'. It's such a common use case that I'd love it if it was supported. PS. I deleted my previous reply to you as I thought I was in a different bug report so my context was incorrect. |
Has anyone created a behavior for this yet? |
Something new with this issue? |
In my case, this happens on CollectionView and ListView on iOS only (so far), and even on iOS, it only happens on physical device. So below is how I worked-around the issue: private double width = 0;
In this scenario, I know what is the height of the collection view should be, so deduct a value from the screen height does the trick. A little nasty, but works for me... |
can you share a project in xamarin form on how to implement your solution @jerryhuang-net |
Faced with the same issue and find this.
After this change items inside CollectionView started to display correctly. |
+1 |
1 similar comment
+1 |
I can confirm the above worked for me on a slighlty different context. In my case, I was setting |
I've had success with this (from https://stackoverflow.com/questions/68440238/how-to-set-auto-height-of-collection-view-in-xamarin-forms)
|
I used VerticalOptions="FillAndExpand" for the entire "DataTemplate" and it is working for me. |
Summary
I was hoping for CollectionView to adapt its height after it's content (When ItemsLayout is set as vertical as it is in default that is). Which just like UICollectionView in native iOS .
The text was updated successfully, but these errors were encountered: