how to use scrollTo method in scrollView ?
Hi, I have a scrollView which has the contentHeight = 500. There are 3 buttons arranged vertically which has three different top, 0, 200, and 300. When I click on the last button which has top 300, scrollView should scroll to 300 from the top of scrollView 0.
Here is my code:
scrollView = Titanium.UI.createScrollView({
contentHeight: 500,
top:0,
showVerticalScrollIndicator:true
});
button1 = Titanium.UI.createButton({
text: "Button 1",
top: 0
});
button2 = Titanium.UI.createButton({
text: "Button 2",
top: 200
});
button3 = Titanium.UI.createButton({
text: "Button 3",
top: 300
});
button3.addEventListener("click", function(){
//Set scrollView scroll to 300 from the top
scrollView.scrollTo(0, 300);
});
But I didn't see anything happens after I tried this code. Please give me some suggestions. Thank you.
1 Answer
-
Possible Answer 1: Add Buttons to ScrollView
I assume you are adding the buttons to the
scrollView
and then thescrollView
to thewindow
? If not, that is the issue.Possible Answer 2: Height is Less than Platform Height
If the height of the device is greater than or equal to 500 then there shouldn't be any need to scroll. Perhaps add the buttons to a window with a height greater than 500, say 1000, and then add the window to the
scrollView
.Conclusion
I'm thinking it's the 2nd answer or something related. Using Ti Mobile 1.6.1 and Android 1.6 I have successfully used
scrollTo
in a number of instances.