GridLayout 和 StackLayout UI 在 Nativescript 中设计

GridLayout and StackLayout UI Design in Nativescript

我正在尝试设计一个登录页面,其中包含需要在登录或注册时显示的表单字段。以下是我的代码:

<FlexboxLayout class="page">
    <StackLayout class="form">
        <Image class="logo" src="~/assets/images/logo.png"></Image>
        <Label class="header" v-show="isLoggingIn" textWrap="true" text="Welcome"></Label>
        <Label class="header" v-show="!isLoggingIn" textWrap="true" text="Register"></Label>
        <label class="subtitle" v-show="isLoggingIn" textWrap="true" text="Already have account? Login with your credentials"></label>
        <label class="subtitle" v-show="!isLoggingIn" textWrap="true" text="Fill the details to register!"></label>

        <GridLayout rows="auto, auto, auto">
            <StackLayout row="0" class="input-field">
                <TextField class="input" hint="Your email registered with us" :isEnabled="!processing"
                       keyboardType="email" autocorrect="false"
                       autocapitalizationType="none" v-model="user.email"
                       returnKeyType="next" @returnPress="focusPassword"></TextField>
                <StackLayout class="hr-light"></StackLayout>
            </StackLayout>

            <StackLayout row="1" class="input-field">
               <TextField class="input" ref="password" :isEnabled="!processing"
                       hint="Your password" secure="true" v-model="user.password"
                       :returnKeyType="isLoggingIn ? 'done' : 'next'"
                       @returnPress="focusConfirmPassword"></TextField>
               <StackLayout class="hr-light"></StackLayout>
            </StackLayout>

            <StackLayout row="2" v-show="!isLoggingIn" class="input-field">
                 <TextField class="input" ref="confirmPassword" :isEnabled="!processing"
                        hint="Confirm password" secure="true" v-model="user.password_confirmation"
                        returnKeyType="next" @returnPress="focusFirstName"></TextField>
                  <StackLayout class="hr-light"></StackLayout>
             </StackLayout>

             <StackLayout row="3" v-show="!isLoggingIn" class="input-field">
                  <TextField class="input" ref="firstName" :isEnabled="!processing"
                         hint="First Name" v-model="user.first_name" autocorrect="false"
                         autocapitalizationType="none" returnKeyType="next" @returnPress="focusLastName"></TextField>
                   <StackLayout class="hr-light"></StackLayout>
              </StackLayout>

              <StackLayout row="4" v-show="!isLoggingIn" class="input-field">
                   <TextField class="input" ref="lastName" :isEnabled="!processing"
                          hint="Last Name" v-model="user.last_name" autocorrect="false"
                          autocapitalizationType="none" returnKeyType="next" @returnPress="focusMobile"></TextField>
                    <StackLayout class="hr-light"></StackLayout>
               </StackLayout>

               <StackLayout row="5" v-show="!isLoggingIn" class="input-field">
                    <TextField class="input" ref="mobile" :isEnabled="!processing"
                           hint="Mobile Number" v-model="user.mobile" autocorrect="false"
                           autocapitalizationType="none" returnKeyType="done"></TextField>
                     <StackLayout class="hr-light"></StackLayout>
                </StackLayout>

                <ActivityIndicator rowSpan="6" :busy="processing"></ActivityIndicator>
        </GridLayout>

        <Button :text="isLoggingIn ? 'Log In' : 'Sign Up'" :isEnabled="!processing" @tap="submit" class="btn btn-primary m-t-20"></Button>
        <Label *v-show="isLoggingIn" text="Forgot your password?" class="login-label" @tap="forgotPassword()"></Label>

    </StackLayout>

    <Label class="login-label sign-up-label" @tap="toggleForm">
        <FormattedString>
            <Span :text="isLoggingIn ? 'Don’t have an account? ' : 'Back to Login'"></Span>
            <Span :text="isLoggingIn ? 'Sign up' : ''" class="bold"></Span>
        </FormattedString>
    </Label>
</FlexLayout>

我可以完美登录屏幕

但每当我尝试注册字段时,我只得到 3 个字段:

未显示所有字段。帮帮我。谢谢

那是因为您最初只为 GridLayout 声明了 3 行 (rows="auto, auto, auto")。如果您将 0 to 2 以外的任何内容分配给 GridLayout 的任何子元素上的 row 属性,它将无效并且永远不会显示。

另外不建议使用GridLayout,如果你只是想让项目垂直堆叠,使用StackLayout。像,

<GridLayout>
    <StackLayout>
        ...
        <StackLayout v-show="!isLoggingIn" class="input-field">
        ...
        </StackLayout>
        ...
    </StackLayout>
    <ActivityIndicator :busy="processing"></ActivityIndicator>
</GridLayout>