Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin 如何在StackLayout等宽中放置3个按钮_Xamarin_Xamarin.forms - Fatal编程技术网

Xamarin 如何在StackLayout等宽中放置3个按钮

Xamarin 如何在StackLayout等宽中放置3个按钮,xamarin,xamarin.forms,Xamarin,Xamarin.forms,有人知道如何在StackLayout中等宽放置3个按钮吗?我让它与网格一起工作 <Grid x:Name="MyGrid" Grid.Row="0" BindingContext="{x:Reference Name=Button1}" HeightRequest="{Binding Width}"> 我想找到一种方法,在没有网格的情况下,以相同的宽度在同一行上显示3个按钮 例如,在StackLa

有人知道如何在
StackLayout
中等宽放置3个按钮吗?我让它与网格一起工作

<Grid x:Name="MyGrid" Grid.Row="0" BindingContext="{x:Reference Name=Button1}"  HeightRequest="{Binding Width}">

我想找到一种方法,在没有网格的情况下,以相同的宽度在同一行上显示3个按钮 例如,在
StackLayout


[按钮1][按钮222][按钮333]

仍在使用网格,只需指定以百分比表示的列宽度(为好玩而设置的列间距):


更新:在Xamarin中使用单行ColumnDefinitions属性。Forms 4.8

RelativeLayout:

<RelativeLayout HorizontalOptions="FillAndExpand">
    <Button Text="Button 1" RelativeLayout.XConstraint="{ConstraintExpression 
            Type=RelativeToParent,Property=Width,Factor=.0000,Constant=0}"
            RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,
            Property=Width,Factor=.3333,Constant=0}"/>
    <Button Text="Button 222" RelativeLayout.XConstraint="{ConstraintExpression
            Type=RelativeToParent,Property=Width,Factor=.3333,Constant=0}"
            RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,
            Property=Width,Factor=.3333,Constant=0}"/>
    <Button Text="Button 333333" RelativeLayout.XConstraint="{ConstraintExpression
            Type=RelativeToParent,Property=Width,Factor=.6666,Constant=0}"
            RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,
            Property=Width,Factor=.3333,Constant=0}"/>
</RelativeLayout>

堆栈布局:

<StackLayout Orientation="Horizontal">
    <Button x:Name="button1" Text="Button 1"/>
    <Button Text="Button 222" WidthRequest="{Binding Path=Width, Source={x:Reference button1}}"/>
    <Button Text="Button 333333" WidthRequest="{Binding Path=Width, Source={x:Reference button1}}"/>
</StackLayout>



看起来像是一条老线索,但对于任何想要使用
StackLayout
实现的人来说,这将准确地在水平方向上以相等的间距放置按钮。

这看起来是一个比我使用网格更好的解决方案。谢谢你的想法。我会等着看是否有人对StackLayout有好主意。如果没有,我会将此标记为已接受的答案。这似乎不会填充整个水平空间,而只有
StackLayout
的子级具有相同宽度的内容时,这才有效。如果所有子项都包含不同的内容(例如,
Grid
s,每个子项都有不同的内容,而不是
Button
s),则它们的间距将不相等。是的!对。但问题是等宽按钮的间距。
<StackLayout Orientation="Horizontal">
    <Button x:Name="button1" Text="Button 1"/>
    <Button Text="Button 222" WidthRequest="{Binding Path=Width, Source={x:Reference button1}}"/>
    <Button Text="Button 333333" WidthRequest="{Binding Path=Width, Source={x:Reference button1}}"/>
</StackLayout>
<StackLayout VerticalOptions="EndAndExpand" Orientation="Horizontal" Spacing="2" Padding="2">
            <Button Text="Move Up" HorizontalOptions="FillAndExpand" BackgroundColor="AntiqueWhite" TextColor="Black" />
            <Button Text="Move Down" HorizontalOptions="FillAndExpand" BackgroundColor="AntiqueWhite" TextColor="Black" />
            <Button Text="Move Right" HorizontalOptions="FillAndExpand" BackgroundColor="AntiqueWhite" TextColor="Black" />
            <Button Text="Move Left" HorizontalOptions="FillAndExpand" BackgroundColor="AntiqueWhite" TextColor="Black" />
</StackLayout>