当前位置:网站首页>[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
边栏推荐
- Feature (5): how to organize information
- AutoCAD - layer Linetype
- Notes de base sur les plans illusoires d'IA (triés en 10 000 mots)
- UE5——AI追逐(藍圖、行為樹)
- Junit5 supports suite methods
- A model can do two things: image annotation and image reading Q & A. VQA accuracy is close to human level | demo can be played
- About the college entrance examination
- Project practice, redis cluster technology learning (6)
- MySQL index
- Summary of demand R & D process nodes and key outputs
猜你喜欢
随机推荐
Mobile mall app solution: how much is it to make an app? Detailed explanation of APP mall development content
【避坑指南】Unity3D项目接入腾讯Bugly工具时遇到的坑
ue4材质的入门和原理笔记
VLAN experiment
Delivery mode design of Spartacus UI of SAP e-commerce cloud
UE5——AI追逐(蓝图、行为树)
Junit4 runs MVN test test suite upgrade scheme
虛幻AI藍圖基礎筆記(萬字整理)
Sum the two numbers to find the target value
渗透测试的介绍和防范
Blender model import UE, collision settings
Introduction et prévention des essais de pénétration
Project practice, redis cluster technology learning (16)
High level application of SQL statements in MySQL database (II)
Introduction and Principle notes of UE4 material
Alibaba cloud ack introduction
【虚幻】按键开门蓝图笔记
ERROR 1118 (42000): Row size too large (> 8126)
Junit5 supports suite methods
Alibaba cloud SLS log service