K
K
kudim2017-09-04 01:53:34
C++ / C#
kudim, 2017-09-04 01:53:34

Is it possible to add elements to Scroll View from different sides (ends)?

Hello!
Actually a question in a subject. But I will describe the problem in more detail.
There is Canvas, added Scroll View to it. Then I created a prefab. And I wrote a script that dynamically creates instances of the prefab and adds them to the Scroll View. And of course, he adds them every time from the same side. But let's say I wanted every third instance to go to the other end of the list (Scroll View). Is it possible to implement this?
And a global problem. I want to implement pull-to-refresh for the same scroll.
There is a list of elements. After I scrolled to the top of the list, I want new elements to load, for this I delay the screen (as sometimes I have to do on the phone so that the news feed loads or the page refreshes). I catch this event (pull) and generate new elements, but when they are added to the list, they fall to the very bottom, but I wanted them to appear at the top of the list. Same question. Is it possible to implement this?
I will be glad for any help. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Basmanov, 2017-09-04
@kudim

The unity UI uses the index of the transform in the hierarchy relative to the parent to sort elements. You can work with this index using the Transform.GetSiblingIndex and Transform.SetSiblingIndex methods . Specifically, for the example with pulling and updating , the Transform.SetAsFirstSibling method is useful , just keep in mind that the update will be jerky, if you want to get smooth animation, you will have to use tricks, or write your own class for a scrollable list.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question