ScrollView的滑动调整
2026/5/8 10:46:20 网站建设 项目流程

在Content下添加上图组件,调整合适的Spacing。调整其他参数。

修改Scroll View上的组件Scroll Rect参数为上图显示(根据实际情况调整)。

代码部分:

string[] strButtonName = fileContent.Split("#"); if (strButtonName.Length>4) { scrollView.content.GetComponent<ContentSizeFitter>().horizontalFit = ContentSizeFitter.FitMode.PreferredSize; scrollView.content.sizeDelta = new Vector2((4 * buttonPrefab.transform.GetComponent<RectTransform>().rect.width) + (4 - 1) * scrollView.content.GetComponent<HorizontalLayoutGroup>().spacing, 2 * buttonPrefab.transform.GetComponent<RectTransform>().rect.height); } else { scrollView.content.GetComponent<ContentSizeFitter>().horizontalFit = ContentSizeFitter.FitMode.Unconstrained; scrollView.content.sizeDelta = new Vector2(770,120); } scrollView.content.GetComponent<HorizontalLayoutGroup>().childAlignment = TextAnchor.MiddleCenter;

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询