Xml Xamarin.Forms是相对于直接容器的网格位置吗?
这个让我困惑。。。如果我有一个网格,假设5列乘5列 现在我在col=1和colwidth=3处放置了一个3列stacklayout(称为SL1)。这将使SL1水平居中,在两侧留下一个空白列Xml Xamarin.Forms是相对于直接容器的网格位置吗?,xml,xamarin.forms,Xml,Xamarin.forms,这个让我困惑。。。如果我有一个网格,假设5列乘5列 现在我在col=1和colwidth=3处放置了一个3列stacklayout(称为SL1)。这将使SL1水平居中,在两侧留下一个空白列 在SL1内部,我有另一个stacklayout(SL2)。如果我为SL2指定网格位置,它是相对于SL1还是相对于整个网格结构的绝对位置?换句话说,第1列是SL2的中间列还是整个网格中第5列的第2列?因此这一列很容易测试。但是你会发现你的两个选择都不是事实,我会提供一些背景资料 首先,让我们构建您的测试用例:
在SL1内部,我有另一个stacklayout(SL2)。如果我为SL2指定网格位置,它是相对于SL1还是相对于整个网格结构的绝对位置?换句话说,第1列是SL2的中间列还是整个网格中第5列的第2列?因此这一列很容易测试。但是你会发现你的两个选择都不是事实,我会提供一些背景资料 首先,让我们构建您的测试用例:
<Grid BackgroundColor="DarkOrange">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="40"></RowDefinition>
</Grid.RowDefinitions>
<StackLayout Grid.Column="1" Grid.ColumnSpan="3" BackgroundColor="DeepSkyBlue" HorizontalOptions="FillAndExpand">
<StackLayout Grid.Column="2" BackgroundColor="Red" WidthRequest="40" HeightRequest="40" HorizontalOptions="Start"></StackLayout>
</StackLayout>
</Grid>
谢谢你的回复。我确实尝试过测试,但没有使用bg颜色(好主意,谢谢),我无法确定任何东西。好的,那么最佳实践就是只对网格的直接子级使用行/列设置;如果没有网格参数,请留下任何更深的内容?不客气。是的,你可以离开他们,他们什么也不会做。仅当视图直接父对象是
网格时,网格参数才起作用。
<Grid BackgroundColor="DarkOrange">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="40"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Column="1" Grid.ColumnSpan="3" BackgroundColor="DeepSkyBlue" HorizontalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackLayout Grid.Column="2" BackgroundColor="Red" WidthRequest="40" HeightRequest="40" HorizontalOptions="Start"></StackLayout>
</Grid>
</Grid>