环境:unity 2018.4.12f1 mac
原理:image+text+Layout Group+ContentSizeFitter,根据text的文字的多少去改变背景大小,实现展开收起的效果。
新建一个Scrollview,删除scrollbar(根据需求保留与否)。(scrollbar删除运行会对Viewport大小改变,需要自己去重新设置大小。)
Content 添加Vertical Layout Group(勾选ChildControlSize)和ContentSizeFitter(Vertical Fit 选择 preferered Size),ScrollRect 的Horizontal取消勾选。
接下来制作cell。
第一种:img-text-btn结构。
对参数进行设置:
首先是Image:
添加Vertical Layout Group(勾选ChildControlSize和ChildForceExpand)和ContentSizeFitter(Vertical Fit 选择 preferered Size);pivot中心点设置为(0.5,1)(重要)
通过调节Vertical Layout Group的Padding参数来对其image图片和Button图片一样大