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.
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 | | | | | | | | | | +-------------------------+ | +-------------------------------+
Your Answer
Think you can help? Login to answer this question!