当前位置:网站首页>[unity3d] nested use layout group to make scroll view with dynamic sub object height
[unity3d] nested use layout group to make scroll view with dynamic sub object height
2022-07-02 10:24:00 【I want to play games while my hair is heavy】
notes 1: This solution refers to StackOverFlow
notes 2: This solution only uses UGUI Built in components , No wheels
notes 3: Use UGUI Self contained Scroll View Components , because Scroll View and Content All are Unity Own naming , Therefore, its specific functions will not be repeated
How to make a with dynamic sub object height ScrollView
demand
Build a chat interface or other needs according to the specific height of the sub object ( The width is the same ) Dynamically changing interface
Desired effect

Problems encountered
Because the usual practice is ScrollView Under components Content Mount a (Grid/Horizontal/Vertical)LayoutGroup, And then by adjusting LayoutGroup To control the width and height of the sub object , This will cause each sub object to have the same width and height , It is impossible to calculate the height of the sub object ( For example, according to the sub object Text Automatically adjust the height of the whole sub object by the number of words on , So as to adjust the whole ScrollView Height )
Solution
ScrollView Under the Content mount ContentSizeFitter (Vertical Fit = Preferred Size) and Vertical Layout Group(Child Controls Size Width / Height = true),ContentSizeFitter The main function is to adjust according to the width and height of the sub object Content The width and height of ,Child Controls Size Let the sub object control its width and height by itself , Be careful not to choose Child Force Expand , Otherwise, the width and height of the sub object cannot be controlled .
The chat interface is generally composed of avatars and dialog boxes , Then we can go through Add... At the root node Horizontal Layout Group( Because avatars and dialog boxes are generally horizontally arranged ), then Dialog add Vertical Layout Group To control their own vertical height .
You will find Head portrait RectTransform Neither width nor height can be set 了 , Because you use the root node of the sub object Horizontal Layout Group Controls the layout of the avatar and dialog .
It is also easy to set its width and height , as long as Mount on the avatar Layout Element , Then adjust it Min Width/Min Height and Preferred Width/Preferred Height that will do .
A little trick
Now the chat interface is filled from top to bottom ( namely Pivot = (0.5,1)), If you want to go from bottom to top , You need to adjust the parent object Pivot = (0.5,0), The principle is unknown , Please also teach me

Final effect

From the original CSDN Blogger 【 I want to play games with my hair 】https://blog.csdn.net/weixin_37658157/article/details/104558947 Reprint please indicate the source
边栏推荐
- Mysql索引
- 【虚幻】自动门蓝图笔记
- 2837xd code generation module learning (1) -- GPIO module
- Edge computing accelerates live video scenes: clearer, smoother, and more real-time
- Alibaba cloud Prometheus monitoring service
- MPLS experiment
- webUI自动化学习
- [Yu Yue education] University Physics (Electromagnetics) reference materials of Taizhou College of science and technology, Nanjing University of Technology
- allure--常用配置项
- Sum the two numbers to find the target value
猜你喜欢

【虚幻4】从U3D到UE4的转型之路

Blender stone carving

Introduction and Principle notes of UE4 material

Alibaba cloud ack introduction

Tee command usage example

Bookmark collection management software suspension reading and data migration between knowledge base and browser bookmarks

pytest--之测试报告allure配置

Delivery mode design of Spartacus UI of SAP e-commerce cloud

滲透測試的介紹和防範

【虚幻】按键开门蓝图笔记
随机推荐
【Unity3D】嵌套使用Layout Group制作拥有动态子物体高度的Scroll View
UE5——AI追逐(蓝图、行为树)
Project practice, redis cluster technology learning (6)
Illusion -- Animation blueprint, state machine production, character walking, running and jumping action
网络通信学习
【虚幻4】从U3D到UE4的转型之路
Unreal material editor foundation - how to connect a basic material
Nonlinear optimization: steepest descent method, Newton method, Gauss Newton method, Levenberg Marquardt method
webUI自动化学习
【Visual Studio】每次打开一个Unity3D的脚本,都会自动重新打开一个新的VS2017
2021-09-12
MySQL -- time zone / connector / driver type
Commutateur Multi - lentilles Blender
Zlib download and use
Mixed development of uni app -- Taking wechat applet as an example
Blender ocean production
Merge ordered sequence
Career planning and development
[ue5] blueprint making simple mine tutorial
UE5——AI追逐(藍圖、行為樹)