我对NativeScript
很新。我正在关注自己的文件。我正在尝试UI对齐。我无法做到这一点。我正在使用Xcode IDE
并在iOS Simulator
中运行。
Groceries Logo应位于顶部
Textfields应位于中间
注册按钮应位于底部
尝试1
<Page loaded="loaded">
<GridLayout height=auto horizontalAlignment="center" verticalAlignment="center" columns="*" rows="auto,auto,*" backgroundColor="brown">
<Image src="res://logo" stretch="aspectFit" horizontalAlignment="center" verticalAlignment="top" col="0" row="0"></Image>
<GridLayout columns="*" rows="auto,auto,auto" verticalAlignment="center" backgroundColor="lightgray" col="0" row="1">
<TextField class="userTxtFld" id="email" text="{{ email }}" hint="Email Address" keyboardType="email" autocorrect="false" autocapitalizationType="none" col="0" row="0"/>
<TextField secure="true" text="{{ password }}" hint="Password" col="0" row="1"/>
<Button text="Sign in" tap="signIn" col="0" row="2"/>
</GridLayout>
<Button text="Sign up for Groceries" class="link" tap="register" verticalAlignment="bottom" col="0" row="2"/>
</GridLayout>
</Page>
尝试2
<Page loaded="loaded">
<GridLayout height="auto" horizontalAlignment="center" verticalAlignment="center" columns="*" rows="auto,auto,*" backgroundColor="brown">
<Image src="res://logo" stretch="aspectFit" horizontalAlignment="center" verticalAlignment="top" col="0" row="0"></Image>
<GridLayout columns="*" rows="auto,auto,auto" verticalAlignment="center" backgroundColor="lightgray" col="0" row="1">
<TextField class="userTxtFld" id="email" text="{{ email }}" hint="Email Address" keyboardType="email" autocorrect="false" autocapitalizationType="none" col="0" row="0"/>
<TextField secure="true" text="{{ password }}" hint="Password" col="0" row="1"/>
<Button text="Sign in" tap="signIn" col="0" row="2"/>
</GridLayout>
<Button text="Sign up for Groceries" class="link" tap="register" verticalAlignment="bottom" col="0" row="2"/>
</GridLayout>
</Page>
问题
在尝试1中,高度=自动,在尝试2中,高度=&#34;自动&#34;
我需要输出作为尝试1。
我不知道,为什么backgroundcolor
没有显示在 height = auto
我不知道,为什么UI Alignment
没有修复 height =&#34; auto&#34;
如果身高=&#34;自动&#34; 是正确的方式,怎么做输出为尝试1?
请帮助我。
输出
答案 0 :(得分:2)
如果您希望第一行为顶部,第二行为中间,最后一行为底部,那么您应该使用row="auto,*,auto"
来完成该行。
试试这个
<Page loaded="loaded">
<GridLayout height="100%" horizontalAlignment="center" verticalAlignment="center" columns="*" rows="auto,*,auto" backgroundColor="brown">
<Image src="res://logo" stretch="aspectFit" horizontalAlignment="center" verticalAlignment="top" col="0" row="0"></Image>
<GridLayout columns="*" rows="auto,auto,auto" verticalAlignment="center" backgroundColor="lightgray" col="0" row="1">
<TextField class="userTxtFld" id="email" text="{{ email }}" hint="Email Address" keyboardType="email" autocorrect="false" autocapitalizationType="none" col="0" row="0"/>
<TextField secure="true" text="{{ password }}" hint="Password" col="0" row="1"/>
<Button text="Sign in" tap="signIn" col="0" row="2"/>
</GridLayout>
<Button text="Sign up for Groceries" class="link" tap="register" verticalAlignment="bottom" col="0" row="2"/>
</GridLayout>
</Page>
通过使用相同的行号为所有3行并使用rows="*"
,也可以实现相同的输出。
<Page loaded="loaded">
<GridLayout height="100%" horizontalAlignment="center" verticalAlignment="center" columns="*" rows="*" backgroundColor="brown">
<Image src="res://logo" stretch="aspectFit" horizontalAlignment="center" verticalAlignment="top" col="0" row="0"></Image>
<GridLayout columns="*" rows="auto,auto,auto" verticalAlignment="center" backgroundColor="lightgray" col="0" row="0">
<TextField class="userTxtFld" id="email" text="{{ email }}" hint="Email Address" keyboardType="email" autocorrect="false" autocapitalizationType="none" col="0" row="0"/>
<TextField secure="true" text="{{ password }}" hint="Password" col="0" row="1"/>
<Button text="Sign in" tap="signIn" col="0" row="2"/>
</GridLayout>
<Button text="Sign up for Groceries" class="link" tap="register" verticalAlignment="bottom" col="0" row="0"/>
</GridLayout>
</Page>
通过指定相同的行号row="0"
,由于rows="*"
,它们将完全相互重叠。
现在我们将设置相应行的verticalAllignment
来设置它在顶部,底部或中心的位置。