You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<imgsrc="images/chapter4/ios/4.png" alt="Grocery data on iOS"></p>
1317
1317
<p>At this point you have a list of data associated with each account that you display in a list view control, but a grocery list isn’t very useful if you can’t add to the list. Let’s look at how to do that next.</p>
1318
1318
<h3id="gridlayout">GridLayout</h3>
1319
-
<p>Introduce what a grid layout actually is. Should be able to copy from the existing guide liberally.</p>
1319
+
<p>In order to allow users to add to their grocery lists you need to add a few additional UI controls to the list page. While you could layout these elements with a <code><StackLayout></code>, let’s look at how to create a slightly more complex layout using the <code><GridLayout></code> element.</p>
1320
1320
<h4class="exercise-start">
1321
-
<b>Exercise</b>: ???
1321
+
<b>Exercise</b>: Add a GridLayout
1322
1322
</h4>
1323
1323
1324
-
<p>Open <code>app/pages/list/list.html</code> and paste in the following code:</p>
1324
+
<p>Open <code>app/pages/list/list.html</code> and replace the contents of the file with the following code:</p>
<p>The outer grid layout’s <code>rows</code> attribute divides the screen into two rows, the first auto-sized according to its childrens' height, and the other to contain *, or the remaining height of the screen. You place UI elements into these rows using the zero-based <code>row</code> attribute. You place inner grid layout in the top row with the <code>row="0"</code> attribute, and the list view in the bottom row with the <code>row="1"</code> attribute.</p>
1352
+
<p>Grid layouts can also divide the screen into columns, which is what the inner grid layout does:</p>
<p>Here the <code>columns</code> attribute divides the top of the screen into two columns. The <code>col="0"</code> attribute puts the text field in the first column, and the <code>col="1"</code> attribute puts the plus image in the last column. Grid layouts are the most commonly used NativeScript layout, so you may wish to take a minute to play around with the <code>columns</code> and <code>rows</code> attributes to figure out how they work.</p>
1359
+
<blockquote>
1360
+
<p><strong>TIP</strong>:</p>
1361
+
<ul>
1362
+
<li>You can nest any of the <ahref="http://docs.nativescript.org/ui/layout-containers.html">NativeScript layouts</a>—not just grid layouts.</li>
1363
+
<li>You can pass numbers, percentages, and a variety of other values to create more complex grid layouts. Refer to the <ahref="http://docs.nativescript.org/ui/layout-containers.html#gridlayout">grid layout docs</a> for more information.</li>
1364
+
</ul>
1365
+
</blockquote>
1366
+
<p>Now that we have the UI ready, let’s make the add button work.</p>
Copy file name to clipboardExpand all lines: src/chapters/chapter4.md
+34-5
Original file line number
Diff line number
Diff line change
@@ -395,13 +395,13 @@ At this point you have a list of data associated with each account that you disp
395
395
396
396
### GridLayout
397
397
398
-
Introduce what a grid layout actually is. Should be able to copy from the existing guide liberally.
398
+
In order to allow users to add to their grocery lists you need to add a few additional UI controls to the list page. While you could layout these elements with a `<StackLayout>`, let’s look at how to create a slightly more complex layout using the `<GridLayout>` element.
399
399
400
400
<h4 class="exercise-start">
401
-
<b>Exercise</b>: ???
401
+
<b>Exercise</b>: Add a GridLayout
402
402
</h4>
403
403
404
-
Open `app/pages/list/list.html` and paste in the following code:
404
+
Open `app/pages/list/list.html` and replace the contents of the file with the following code:
405
405
406
406
``` XML
407
407
<GridLayout rows="auto, *">
@@ -422,9 +422,38 @@ Open `app/pages/list/list.html` and paste in the following code:
422
422
423
423
<div class="exercise-end"></div>
424
424
425
-
Show an image of what this looks like first and then break down the syntax in detail.
425
+
When your app runs with these changes your UI should now look like this:
426
+
427
+

428
+

429
+
430
+
To break down how this layout works, let’s start with the outer structure of the markup:
The outer grid layout’s `rows` attribute divides the screen into two rows, the first auto-sized according to its childrens' height, and the other to contain *, or the remaining height of the screen. You place UI elements into these rows using the zero-based `row` attribute. You place inner grid layout in the top row with the `row="0"` attribute, and the list view in the bottom row with the `row="1"` attribute.
440
+
441
+
Grid layouts can also divide the screen into columns, which is what the inner grid layout does:
442
+
443
+
```XML
444
+
<GridLayout columns="*, auto"class="add-bar">
445
+
<TextField col="0"></TextField>
446
+
<Image col="1"></Image>
447
+
</GridLayout>
448
+
```
449
+
450
+
Here the `columns` attribute divides the top of the screen into two columns. The `col="0"` attribute puts the text field in the first column, and the `col="1"` attribute puts the plus image in the last column. Grid layouts are the most commonly used NativeScript layout, so you may wish to take a minute to play around with the `columns` and `rows` attributes to figure out how they work.
451
+
452
+
> **TIP**:
453
+
> * You can nest any of the [NativeScript layouts](http://docs.nativescript.org/ui/layout-containers.html)—not just grid layouts.
454
+
> * You can pass numbers, percentages, and a variety of other values to create more complex grid layouts. Refer to the [grid layout docs](http://docs.nativescript.org/ui/layout-containers.html#gridlayout) for more information.
426
455
427
-
Now let’s make the add button actually work.
456
+
Now that we have the UI ready, let’s make the add button work.
0 commit comments