Xamarin中按钮之间的奇怪空间

时间:2018-10-05 06:54:55

标签: user-interface xamarin margins stacklayout

我正在Xamarin中的一小部分UI中工作,只是一张带有一些标签和两个按钮(作为一列)的“卡片”。在这里您可以看到我的Xaml:

<Grid BackgroundColor="White" RowSpacing="0" ColumnSpacing="0" Margin="10,10,10,0">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="80"/>
    </Grid.ColumnDefinitions>

    <StackLayout Grid.Column="1" 
                 Spacing="0" 
                 BackgroundColor="PaleGoldenrod">
        <Button Text="OPEN" Margin="0" 
                VerticalOptions="FillAndExpand" 
                HeightRequest="70"/>
        <Button Text="RESET" Margin="0" 
                VerticalOptions="FillAndExpand" 
                HeightRequest="70"/>
    </StackLayout>

    <Label TextColor="Black" Margin="5">Relojes</Label>
    <Label  HorizontalTextAlignment="End" 
            TextColor="Black" 
            Margin="5">Sin Tocar</Label>
</grid>

在这里您可以看到我所拥有的照片:

enter image description here

我想删除两个按钮之间的空间,以使它们在四周均匀分布。我尝试将上方按钮的下边距设置为-2.5,底部按钮的上边距设置为-2.5,看起来不错,但是..必须有一个更清洁的选项。 知道吗??

1 个答案:

答案 0 :(得分:0)

Spacing中使用StackLayout来缩小控件之间的空间。这里的Spacing为负。

<StackLayout  Grid.Column="1" 
Spacing="-8" 
BackgroundColor="PaleGoldenrod">
<Button Text="OPEN" Margin="0" 
VerticalOptions="FillAndExpand" 
HeightRequest="70"/>
<Button Text="RESET" Margin="0" 
VerticalOptions="FillAndExpand" 
HeightRequest="70"/>
</StackLayout>

enter image description here

相关问题