⚠️ This lesson is retired and might contain outdated information.

Add Responsive Wrapping Using WrapLayout

Brad Martin
InstructorBrad Martin
Share this video with your friends

Social Share Links

Send Tweet
Published 8 years ago
Updated 2 years ago

We will use the WrapLayout component to create a layout that wraps UI widgets to a new row or column if no space is left in a NativeScript app.

[00:00] Start by adding a wrap layout to your page. And we're going to set a width on the wrap layout, so we can really see the visual effect once we run this. Inside of the wrap layout, we need a few view components to fill the space. We'll start with a label, put the text set to 'hello'. And we're also going to use background color to really see the wrap layout here in effect.

[00:30] We'll add another label with the text 'goodbye', background color of yellow, another label with the text of 'egghead', background color 23489DBE as a hex. And last, we use another label with the text 'set to go home' and background color equal to pink. And again, to see this in effect, we're going to set a few properties that you might not normally need, such as the width on these child items. And we're going to use '70' on each of these labels.

[01:22] And when we run this, we should see three items on the first row and this last label should wrap. And here, you see the first label, the second label, third, and fourth. The fourth label is wrapped because all four items have greater width, when they're combined, than the entire wrap layout of 250. If we change this to 280, which would be the sum of the four labels' widths, they should be on one row. And here, you see one, two, three, four all on the first row.

[02:02] The wrap layout also provides the orientation property, which you can set to vertical. The default is horizontal. When you run this, the wrap will present items in a column.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today