I have searched for many tutorials on ui::Scrollview in cocos2dx v3.4 but found none.
All I found is how to create a ScrollView which I have already done.
I want to add images and scroll them vertically such that the image at the center is slightly bigger than the other images. The description has been shown in the below picture.
EDIT: Changed the image for more clarity. Only the light yellow colored part is visible.
After Scrolling:
Can anyone give me an idea of how to do it or share some code?
This seems like a perfect use case for a listview? Something like this. Basically create a listview and then create a bunch of layouts with a child of the box sprite.
Does that mean, I have to create all my sprites, add them to the layout and add the layout to ListView?
or
Do I have to create multiple layouts with each layout having a single sprite?
EDIT: I have added multiple layouts to the ListView. How do I make the focused layout look big like in the 2nd image given above.
I have the scrollView set. How can I make the image at center appear bigger than the other images when scrolled and how do I get the tag of each image when it is at the center!
Btw, I dont use Cocos Studio.
Does the co-ordinate system change for UI Elements?
I have added images to my scrollview. The below images represent my ScrollView. The light yellow is the scrollView. The height of InnerContainer is high.Hence, the other images are outside the yellow box.
Please, someone help me in zooming the the image which comes to center of the scrollView everytime. Refer the images in the first post for more clarity.
Ok, so your question is slightly different know (I think). You basically want zoom into a middle image (ie. scale it up). You can obviously do it yourself for the image that is initially the middle image. After that, I think the right way to do this would be to add an eventcallback:
scrollView->addEventListener()
and have the event listener determine what image is the middle image and scale it up. Make all the other images go back to a scale of 1.
Do you want to post your code in this thread? Don’t override the OnTouchMoved method. Create a callback function instead. Your code will look something like this:
void MyClass::scrollCallBack(cocos2d::Ref* sv, cocos2d::EventType event) {
auto scrollView = static_cast<cocosd::ui::ScrolView*>(sv);
if (event == cocos2d::EventType::SCROLLING) {
// Do stuff here to the scrollView.
}
}
Overriding onTouchMoved is a bad idea. svCallBack is a callback that is run every time an “action” happens to the scrollView. Take a look at the addEventListener function on scrollview objects (look in the code of a scrollView). The only issues is that the callback is called_before_ the scrollView moves the innercontainer. That said since the moves should be incrementally small I don’t think it’s a huge issue.
Alternatively, just put something in the update function of the parent of the scrollView that checks each frame what the middle object is on the scrollView and scales that up or down as needed.