到目前为止,我尝试过的是:
<ListView RowHeight="50">
<ListView.Header>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="49" />
<RowDefinition Height="1" />
</Grid.RowDefinitions>
<Label Grid.Row="0" BackgroundColor="#EEEEEE" Text="ABC" />
<BoxView Grid.Row="1" BackgroundColor="#999" HeightRequest="1" />
</Grid>
</ListView.Header>
<ListView.ItemTemplate>我本以为会看到一个顶级区域的颜色EEE和低于1和999颜色的线条。
然而,在EEE颜色和999线之间有一个白色区域,大约3-4 px高。
有人知道为什么会出现这种情况吗?我怎样才能改变它,使999线直接出现在EEE颜色区域的下方?
发布于 2017-08-15 23:30:56
我认为这是因为网格(6)的默认RowSpacing值*。设置<Grid RowSpacing="0">来摆脱它。
*见更多https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Core/Grid.cs。
尽管如此,如果您的布局与所显示的完全相同,我建议您使用StackLayout (与Spacing="0"一起使用)而不是网格。如下所示:
<StackLayout Spacing="0">
<Label BackgroundColor="#EEEEEE"
Text="ABC"
HeightRequest="49"/>
<BoxView BackgroundColor="#999"
HeightRequest="1" />
</StackLayout>结果(第一次是网格,第二次是StackLayout):

发布于 2017-08-15 23:40:45
在上面的行上使用负边距,因此您的"ABC“行使用-6的底部边距。
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="49" />
<RowDefinition Height="1" />
</Grid.RowDefinitions>
<Label Grid.Row="0" BackgroundColor="#EEEEEE" Text="ABC" Margin="0,0,0,-6" />
<BoxView Grid.Row="1" BackgroundColor="#999" HeightRequest="1" />
</Grid>https://stackoverflow.com/questions/45702901
复制相似问题