Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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,

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.

— asked October 11th 2010 by Den Cambodia
  • scrollto
  • scrollview
1 Comment
  • I too am not noticing anything when using scrollTo. Did you figure this out?

    — commented February 9th 2011 by Hamish Rouse

1 Answer

  • Possible Answer 1: Add Buttons to ScrollView

    I assume you are adding the buttons to the scrollView and then the scrollView to the window? 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.


    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.

    — answered April 5th 2011 by Joe iEntry
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.