Android scrollView no momentum when scrolling

You must Login before you can answer or comment on any questions.

Hey,

I have an app which has a tableView inside a scrollView. On iOS it is all fine but on Android, when scrolling, it is like there is no momentum, as soon as I get my finger off the screen, it stops scrolling. This feels very awkward. Is there any way to have momentum when scrolling in a scrollView (like on iOS) ?

Here some cleaned up code I am using for this:

// the wrapper window that will hold all views for this tab
var self = Ti.UI.createWindow({
  title: title,
  backgroundImage: 'images/background.png'
});
 
// require our 'stlyesheet'
var style = require( '/ui/styles' );
 
/* -------------------------------------------
 * Prescription Refill Form
 * ---------------------------------------- */
// the scrollView that will hold our form
var scrollable = Ti.UI.createScrollView({
  'layout': 'vertical'
});
 
// we'll create the tableView at the bottom because.. 
// each field is a tableRow containing two cell.. most of the time.
// this array will contain all rows to add to the table
var rows = [];
// also keep track of each fields
var fields = [];
 
    /* -------------------------------------------
     * Instructions
     * ---------------------------------------- */
    // create a tableRow view
    var ir = Ti.UI.createTableViewRow( style.row.info );
    ir.height = '68dp';
 
      // add a label in our row
      var il = Ti.UI.createLabel(
        style.merge(
          style.label.default, {
            text: 'To refill a prescription please provide the information below:',
            color: style.color.black,
            font: style.font.normal
          }
        )
      );
      // add the label to the table tow
      ir.add( il );
 
    // we done with this row, add it to the array of rows
    rows.push( ir );
 
  //
  // I am adding 8 more row like the one above
  //
 
  // set the data for the table (set the rows)
  // must set the data when creating the object or else we can't access the
  // rows afterward....
  // table.setData( rows );
  var table = Ti.UI.createTableView({
    // top: '10dp',
    backgroundColor: 'transparent',
    separatorColor: 'transparent',
    data: rows,
    height: '899dp',
    width: '100%'
  });
 
  // add the table to the scrollable view
  scrollable.add( table );
 
// add the scrollView that hold our form
self.add(scrollable);
I am using SDK 2.1.0 GA on Max OSX 10.7.4. This is happening on Android 4.0.3 and 4.1, on both the emulator and real devices - have not tested this on Gingerbread yet.

Thanks,

Nicolas

2 Answers

Accepted Answer

General guidance is that you should not put any type of scrolling view inside another scrolling view. So don't put a WebView inside a ScrollView or a TableView inside a ScrollView.

I'm not sure I see what you're doing with the fields array. If you really only have 9 rows that are text rows, then just put them in a TableView and add the TableView to self (skip the ScrollView entirely).

On the other hand, if you're building a form, why use a TableView at all?

If you really must have a TableView inside a ScrollView, one option is presented here.

— answered 10 months ago by Jason Priebe
answer permalink
4 Comments
  • Are you suggesting that a tableView will automatically scroll if whatever it contains is bigger (higher) than the device screen height ? I'm still new to all this and just assumed it needed to be in a scrollView. I tried removing the scrollView and adding the table directly to self but the view get centered vertically and won't scroll.

    Yes, I am building a form, the tableView is because this is how I managed to style it the way I wanted.. The fields array contains a reference to all my form text fields. This is how I managed to get the value of each field later in my code.

    — commented 10 months ago by Nicolas Duvieusart Déry

  • Yes, a TableView automatically scrolls if the content is bigger than the screen height.

    Try setting top and bottom to 0 to have the TableView fill the screen. Then add enough lines to make it "overflow". As long as the TableView's scrollable property is true (which is the default), it should scroll.

    I still don't quite understand how you're building a form inside a TableView. Mind sharing a screenshot?

    — commented 10 months ago by Jason Priebe

  • Concerning the tableView, I don't see any scrollable parameters for Titanium.UI.TableView. I've added it just to be sure and works! Also fixed my no "momentum" scrolling so that's good!

    Concerning the form, I've attached a screenshot of the app (we'll, linked to an image), basically, each row contain a label and a textField. I've tried using a commonJS that claims to do form before but it was really hard to style it the way I needed to.

    http://download.nddery.ca/campus.screenshot.png

    — commented 10 months ago by Nicolas Duvieusart Déry

  • Show 1 more comment

I would not use a TableView for that.

I would add the controls to a ScrollView. Set the layout for the ScrollView to 'vertical', then add each control with a top of "10dp" or so, and they will be laid out for you.

You actually might want to wrap each label/control in a view of its own:

+-------------------------------+
|  Window                       |
|  +-------------------------+  |
|  | ScrollView              |  |
|  |                         |  |
|  | +---------------------+ |  |
|  | | View                | |  |
|  | |                     | |  |
|  | | Label     TextField | |  |
|  | +---------------------+ |  |
|  |                         |  |
|  | +---------------------+ |  |
|  | | View                | |  |
|  | |                     | |  |
|  | | Label     TextField | |  |
|  | +---------------------+ |  |
|  |                         |  |
|  | +---------------------+ |  |
|  | | View                | |  |
|  | |                     | |  |
|  +-------------------------+  |
+-------------------------------+

— answered 10 months ago by Jason Priebe
answer permalink
4 Comments
  • You are right, but unfortunately time is ticking away. I do agree it would be best though. Do you think Apple could refuse the app as it does not follow general guidelines of a tableView ? If yes, then I guess we'll have to spend the time re-working on the layout.

    Thanks!

    — commented 10 months ago by Nicolas Duvieusart Déry

  • I wish I had more insight into Apple's mysterious ways. It does seem a bit out of the ordinary, and if i t were me, I'd stick to the middle of the road, so as not to attract unwanted attention!

    I think you could rework a form like that in an hour or two. I have no experience with forms libraries. I'm not sure I really see the value of them -- I use them in web development, and they're hugely valuable, especially since you don't have to render HTML by hand. But in a mobile app framework, they don't seem to bring as much value to the table IMHO.

    — commented 10 months ago by Jason Priebe

  • A quick search and replace did the trick, my form is now table less and (at least on Android - iOS was always cool with it), it seems to behave nicer!

    Thanks a lot!

    — commented 10 months ago by Nicolas Duvieusart Déry

  • Show 1 more comment

Your Answer

Think you can help? Login to answer this question!