- Home /
How to set position in ScrollView?
Hello,
How to set position in ScrollView?
For example I have 300 buttons inside ScrollView and want to set position to make 200-th button visible.
Answer by Eric5h5 · May 15, 2010 at 07:58 PM
You can use GUIStyle.CalcHeight to get the height of a line, then set the scrollview .y position to 200*calculatedHeight to go to the 200th button.
Thanks! It's already can give what I need. But there is also some space between lines. In my case it is buttons and space between them. I see that it is 2 pixels, but can't find any variable inside GUIStyle where it could be. Is there a way to calculate it in script? Or may be it's always 2 pixels?
@Santa: Probably whatever the padding or margin is set to for the GUIStyle. However I think that's included in the CalcHeight maybe?
No, it isn't in CalcHeight. Both Padding and $$anonymous$$argin for the button GUIStyle has 4 in all values. And the space between two buttons is 2. I've checked it and one of them is what I need. I've tried to change both from 4 to 16 and got the result. BUT visually it is still 2 pixels, and mathematically I should use more. Interesting.
Your answer
Follow this Question
Related Questions
Scrollable rect containing GUIText/Label 1 Answer
GUIlayout scrollbar, Not working well... 1 Answer
How to disable ScrollView dragging 4 Answers
Suppress Horizontal Scrollbar? 2 Answers
How can I set the mousewheel scroll speed in a ScrollView? 3 Answers