0

I'm building my first Nativescript app with Nativescript-vue and I'm having trouble with the layout of a page.

The Documentation shows you how to layout a page but it isn't too clear on overall usage and I can't see if you can use more than one layout style per page

I'd like to start out using a stacklayout for the top of the page but then display some data in a table so I'm using grid layout for the lower part.

What I'm finding is that when I use more than one layout it only shows the last one on the page

Example: (Only the GridLayout section displays on the page, the stacklayout is invisible)

<template>
  <Page class="page">
<ActionBar class="action-bar" :title="title"/>
<ScrollView>
  <StackLayout>
          <Image :src="img" stretch="aspectFit" v-if="img" />
          <Button class="btn btn-primary" text="Buy Now" @tap="visitPage(url)" v-if="url" />
  </StackLayout>

  <GridLayout columns="auto, auto" rows="2*, 3*">
    <Label text="Author:" row="0" col="0" padding="20px" />
    <Label text="Shakespear" row="0" col="1" padding="20px" />
    <Label text="Publisher" row="1" col="0" padding="20px" />
    <Label text="A publisher" row="1" col="1" padding="20px" />
  </GridLayout>

</ScrollView>
  </Page>
</template>

Q: is there a way to show more than one layout option per page?

4

2 回答 2

1

尽管@Argonitas 的回答是正确的,但您应该避免嵌套布局容器。在这种情况下,将两行添加到 GridLayout 会更好。就像是:

<GridLayout columns="auto, auto" rows="auto, auto, 2*, 3*">
  <Image row="0" col="0"  colSpan="2" :src="img" stretch="aspectFit" v-if="img" />
  <Button row="1" col="0"  colSpan="2" class="btn btn-primary" text="Buy Now" @tap="visitPage(url)" v-if="url" />

  <Label text="Author:" row="2" col="0" padding="20px" />
  <Label text="Shakespear" row="2" col="1" padding="20px" />
  <Label text="Publisher" row="3" col="0" padding="20px" />
  <Label text="A publisher" row="3" col="1" padding="20px" />
</GridLayout>
于 2018-09-05T18:12:20.503 回答
0

ScrollView 只接受一个孩子。但是您可以将 GridLayout 打包到 StackLayout 中:

<ScrollView>
  <StackLayout>
          <Image :src="img" stretch="aspectFit" v-if="img" />
          <Button class="btn btn-primary" text="Buy Now" @tap="visitPage(url)" v-if="url" />

    <GridLayout columns="auto, auto" rows="2*, 3*">
      <Label text="Author:" row="0" col="0" padding="20px" />
      <Label text="Shakespear" row="0" col="1" padding="20px" />
      <Label text="Publisher" row="1" col="0" padding="20px" />
      <Label text="A publisher" row="1" col="1" padding="20px" />
    </GridLayout>
  </StackLayout>

这样,GridLayout 应该出现在 Button 下方。您通常会做的是将图像和按钮打包到 GridLayout 中,以将它们作为一个组进行控制。

于 2018-09-05T08:56:43.287 回答