Titanium Community Questions & Answer Archive

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

scrollView containing tableView layout problem on Android

Having a small issue with scrollView and vertical layouts.

If I set the scrollView contentHeight:'auto', then the VerticalScrollIndicator becomes a small blob in the top of the scroll view and the scroll length area becomes huge. In other words, the "auto" height is failing to calculate the height of the ScrollView when it contains a tableView.

Secondly, the tableView rowheight property doesnt appear to work at all. No matter what you set it to, it is always the same height.


var scrollView = Titanium.UI.createScrollView({backgroundColor:'#fff',contentWidth:parseInt(Titanium.Platform.displayCaps.platformWidth,10)-20,contentHeight:'auto',showVerticalScrollIndicator:true,top:5,borderRadius:6,borderWidth:4});

var copyright = Titanium.UI.createLabel({text:        'Copyright (C) 2010 XXX. All rights Reserved',font:    {fontFamily:'Helvetica Neue',fontSize:12,fontWeight:'bold'},color:'#aaa',bottom:10,height:15,width:parseInt(Titanium.Platform.displayCaps.platformWidth), textAlign:'center'});

Suggestions and recommendations are much appreciated.

— asked March 25th 2010 by Gregor Munro
  • android
  • layout
  • tableview
  • webview
1 Comment
  • I'm having a similar problem on iPhone.

    I don't set the table view height, and set the table view to be
    non-scrollable (because I want the the scroll view to do the
    scrolling). The table view height appears to get set to the containing
    scroll view height and never scrolls.

    If I set the table view height to 'auto', I don't get anything.

    If I set the table view height to some fixed number, It has that fixed
    height and scrolls if the height is > the scroll view height. Of
    course, I want the table view height to increase and decrease as I add
    and remove rows.

    It appears that scroll views don't handle variable sized items. If
    so, it would be good to get that documented.

    — commented November 30th 2010 by Jim Fulton

3 Answers

  • Hey Gregor, The row height problem is definitely a bug..

    The TableView takes up the entire parents viewable area by default, so what you might be seeing is the TableView exapnding the ScrollView to it's maximum height. Can you try setting the height on the tableView to see if it fixes the problem?

    — answered March 26th 2010 by Marshall Culpepper
    1 Comment
    • By setting a set height and width of the tableview and not setting dimensions for the scrollview I was able to get it to display correctly. I used Ti.Platform.displayCaps.platformHeight and platformWidth for the dimensions. You can turn these into percentages by multiplying them by a float number between 0 and 1. Setting the scrollview dimensions without setting tableview dimensions caused it to shrink to odd dimensions and not display right.

      — commented April 4th 2011 by Joe iEntry
  • One thing I should mention – you might also want to take a look at using headerView / footerView of the table view. This allows you to pin a view (or group of views) to the table view so you don't need a "scroll inside a scroll" like you're currently setting up, which can cause strange behavior.

    — answered March 27th 2010 by Marshall Culpepper
    1 Comment
    • This works great for my use case.

      I have a scrollable list of items and I have a view for adding new
      items. Originally, this was just a last item, but I didn't want it to
      be deletable, so I tried making it a peer in a scroll view, which
      didn't work. Making it a footerView works well and is more elegant.
      The only catch for me was that I want to scroll to this input view when
      the window is opened. Before, I used scrollToIndex, but that doesn't
      work for scrolling to the footer and there's no scrollToBottom. My
      hack around was to focus and blur the input text area when the window
      is opened, which seems to work fine. :)

      — commented November 30th 2010 by Jim Fulton
  • Hi Marshall,

    I can set the row height and it works ok, the problem I have is that the tableview is a variable length so I guess I will have to workaround by retrieving the data, counting the number of responses and then multiplying that by the single row height.

    I've also come across a null pointer exception in the same file when loading a UI.ScrollableView which I am trying to pinpoint.

    — answered March 26th 2010 by Gregor Munro
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.