|
Post by nugget on May 16, 2023 19:32:41 GMT
Hi ! I have cell views in my vertical scroller that can have different sizes at runtime. There are a few different prefabs that are instantiated depending on the type of cell view we want to use. The container for the scroller's cell views has a content size fitter component, and the prefabs that will be instantiated have a height of 0 (it will be adjusted by the number of child items put in the prefab).
I have trouble using GetCellView to determine the cells height, I have tried a couple things : - Get the RectTransform.sizeDelta.y of the original prefab, but since the height is 0 all the items are "compressed". - Get RectTransform.sizeDelta.y from the actual cell view (with all its child items), but this seems to cause some "stuttering" when the cells get recycled/put in the scroller, probably because of the size changes offsetting the elements in the list. - Return a static height (different for each prefab type) : works-ish, but since we can have a lot of children in a cell view, it will overflow, not very ideal.
I'm not really good with UI elements, is there a recommended way for handling dynamic cell view sizes, and what kind of UI components should I use for this ?
Thank you !
|
|
|
Post by echo17 on May 17, 2023 9:12:04 GMT
There are a couple of demos that come with EnhancedScroller that can help you out. They each have their advantages / disadvantages:
Demo #8: This one uses Unity's content fitter to calculate how much space is needed for the cell, storing the size in the data (Model). Advantage: Precise size calculation Disadvantage: Every cell has to be created for content fitter to work. This adds a lot of overhead in time and memory usage, so it is not recommended for large sets of data.
Demo #16: This one does a rough calculation of the cell size based on a fixed character width. Advantage: No need to create the cells to get the size, the formula works on the text contents of the data. Disadvantage: It is not precise, especially for fonts that have large variance in their cell widths.
|
|
|
Post by nugget on May 18, 2023 13:06:57 GMT
Alright, I'll check these, thanks for the suggestions !
|
|