2017-08-15 26 views
1

這裏的底部是我試過到目前爲止:添加房客到ListView.Header

<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顏色區域的下方?

回答

3

(對不起,我英文不好)

我想這是因爲電網的默認值RowSpacing(6)。設置<Grid RowSpacing="0">擺脫它。

查看更多here在Grid類的源代碼。

儘管如此,我建議您使用StackLayout(與Spacing="0")而不是Grid,如果您的佈局完全如您所示。就像這樣:

<StackLayout Spacing="0"> 
    <Label BackgroundColor="#EEEEEE" 
      Text="ABC" 
      HeightRequest="49"/> 
    <BoxView BackgroundColor="#999" 
      HeightRequest="1" /> 
</StackLayout> 

結果(先用網,第二,StackLayout):

Sample

+0

有了StackLayout,我還可以指定高度嗎? – Alan2

+0

當然。但在這種情況下,它將在元素中指定,例如'Label HeightRequest =「49」',並且可能需要調整垂直文本對齊。 –

+0

可以舉出一個XAML看起來像什麼的例子。我會接受你的回答 – Alan2

2

使用上面的行負利潤,因此你的「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>