我有个问题 . 我是xaml的新手,我正在尝试使用我的xaml代码创建的4个按钮,我使用我的xaml代码创建的标签 . 现在,我的第一张图片(“我的xaml代码中的图像”)就是我运行xaml代码时的图像 . 然而,当我试图将它全部保持在一个堆栈布局中时,它与我的完成图像(“即时尝试实现图像”)中的任何指针都不匹配,因为我在做错了什么?
<!-- Page -->
<StackLayout
x:Name = "CustomerStackLayout">
<Label
x:Name = "ThisLabel"
Text = "Order #2102"
VerticalOptions= "Start" >
</Label>
<Label
Text = "John Doe"
VerticalOptions ="Start">
</Label>
<Label
Text = "(832)-555-4518"
VerticalOptions ="Start">
</Label>
<Label
Text = "5612 StillWater Dr"
VerticalOptions ="Start">
</Label>
<Label
Text = "Houston, TX 77079"
VerticalOptions ="Start">
</Label>
<Label
Text = "Pickup Time:Mon July 10, 4:30PM"
TextColor = "Yellow"
HorizontalOptions = "Center">
</Label>
<!--AbsoluteLayout.LayoutBounds = "0.975,0.01,100,25-->
<Button
x:Name = "callButton"
Text ="call"
HorizontalOptions = "End"
VerticalOptions = "End"
Clicked = "Handle_Clicked"
BackgroundColor = "Red">
</Button>
<!--AbsoluteLayout.LayoutBounds = "0.975,0.06,100,25"-->
<Button
Text = "text"
x:Name = "textButton"
Clicked = "textButton_Clicked"
BackgroundColor = "Red"
HorizontalOptions = "End"/>
<Button
Text = "map"
HorizontalOptions = "End"
VerticalOptions = "Start"
x:Name = "mapButton"
Clicked="MapsButton_Clicked"
BackgroundColor = "Red"/>
<!--AbsoluteLayout.LayoutBounds = ".7,0.9,104,34"-->
<AbsoluteLayout>
<Button
x:Name = "ImOnItButton"
Text ="Im on it"
Clicked = "ImOnIt_Clicked"
IsVisible = "true"
BackgroundColor = "Red"
AbsoluteLayout.LayoutBounds = ".7,0.9,104,34"/>
<!--AbsoluteLayout.LayoutBounds = ".7,0.9,104,34"-->
<Button
x:Name = "ArrivedButton"
Text = "Arrived"
Clicked ="arrivedButton_Clicked"
IsVisible = "false"
BackgroundColor = "Red"
AbsoluteLayout.LayoutBounds = ".7,0.9,104,34"
/>
</AbsoluteLayout>
</StackLayout>
1 回答
StackLayout将按顺序布置其子项,无论是垂直还是水平 . 由于您没有指定方向,因此隐含垂直,这正是您所看到的 . 顾名思义,孩子们堆叠在一起 .
简短的回答是,您需要比单个StackLayout更复杂的布局 . 您可以使用嵌套的StackLayouts实现您的目标,但这将是艰难的,并且效率低于其他选项 .
至少在设计的顶部,Grid可能是你最好的选择,例如:
您可能不需要Grid的所有VerticalOptions和HorizontalOptions,但这应该是一个不错的起点 .