当前位置:网站首页>[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
边栏推荐
- Blender camera surround motion, animation rendering, video synthesis
- ICLR 2022: how does AI recognize "things I haven't seen"?
- Matlab generates DSP program -- official routine learning (6)
- 两数之和,求目标值
- 2837xd code generation module learning (2) -- ADC, epwm module, timer0
- [unreal] key to open the door blueprint notes
- Blender体积雾
- Illusion -- Animation blueprint, state machine production, character walking, running and jumping action
- Applet development summary
- Project practice, redis cluster technology learning (11)
猜你喜欢

2021-10-04

【Unity3D】嵌套使用Layout Group制作拥有动态子物体高度的Scroll View

Introduction et prévention des essais de pénétration

Ue5 - ai Pursuit (Blueprint, Behavior tree)

The primary market project galaxy will conduct public offering on coinlist on February 17

Network real-time video streaming based on OpenCV

虛幻AI藍圖基礎筆記(萬字整理)

Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer

【Visual Studio】每次打开一个Unity3D的脚本,都会自动重新打开一个新的VS2017

【UE5】蓝图制作简单地雷教程
随机推荐
Project practice, redis cluster technology learning (10)
Project practice, redis cluster technology learning (VII)
Application of rxjs operator withlatestfrom in Spartacus UI of SAP e-commerce cloud
High level application of SQL statements in MySQL database (II)
webUI自动化学习
Network real-time video streaming based on OpenCV
Blender多镜头(多机位)切换
[IDL] Research
Large neural networks may be beginning to realize: the chief scientist of openai leads to controversy, and everyone quarrels
Remember a simple Oracle offline data migration to tidb process
2021-10-04
Ctrip starts mixed office. How can small and medium-sized enterprises achieve mixed office?
2021-09-12
Configuration programmée du générateur de plantes du moteur illusoire UE - - Comment générer rapidement une grande forêt
2.14 is it Valentine's day or Valentine's day when the mainstream market continues to fluctuate and wait for changes?
How does {} prevent SQL injection? What is its underlying principle?
【Unity3D】嵌套使用Layout Group制作拥有动态子物体高度的Scroll View
[unreal] animation notes of the scene
What wires are suitable for wiring on bread board?
Project practice, redis cluster technology learning (VIII)