Reputation: 3
I'm doing a scrollable list of values.
I did it using an Item template setted up with Layout Element, nested in a Vertical Layout Group object.
The Item Template is composed by an image and a text description.
The script that i use to populate the list is an easy for:
for (int i = 0; i < details.Count && i < LenSize; i++){
Transform transf = Instantiate(template, container);
RectTransform trasnf2 = transf.GetComponent<RectTransform>();
height = -3 * i;
trasnf2.anchoredPosition = new Vector2(0, height);
transf.gameObject.SetActive(true);
transf.Find("Image").GetComponent<Text>().text = details[i].image;
transf.Find("Desc").GetComponent<Text>().text =
details[i].description;
}
All works properly when I run the app from my PC, I'm able to scroll the list by "left click + drag up/down" or mouse scroll wheel.
My problem appears when i build the app and run it from my android device, i not able to scroll the list with the touchscreen. (Touchscreen inputs work fine, I have some button and they work)
Can someone help me with my problem?
I found that I can use Input manager to catch input event... but I not sure how use it to "scroll" on Android, because if i change offset of object with Vertical Layout Group, I move the entire object and I don't scroll the inside elements, else, if I change offset of child element (Item Templates) I change the single element position "breaking" the layout of the Vertical Layout Group;
I tried to find solutions, but I'm new and apparently nothing works when I apply it.
What am I doing wrong?
Upvotes: 0
Views: 843
Reputation: 6275
If your goal is to make a scrollable list of UI objects here is a gif I made on that process. It runs through the layout and each component and it working.
If you want to dynamically add objects to this list at runtime, use the Panel_Content
transform and instantiate objects using Instantiate(yourPrefab, Pane_Content.transform, false)
. Let me know if you run into issues with this example.
Upvotes: 0