繁体   English   中英

减少Xamarin表单中ListView项之间的间距

[英]reduce spacing between ListView Items in Xamarin forms

我在xamarin便携式应用程序中有此列表,我似乎无法删除或至少减少项目之间的间距,并且也禁用项目选择。

<ListView x:Name="ListGroups" 
           ItemsSource="{Binding Source={x:Static local:Stash.Groups}}" 
           HorizontalOptions="Center" >
   <ListView.ItemTemplate>
    <DataTemplate >
      <ViewCell>
             <Label Text="{Binding Name}" TextColor="Aqua" FontSize="10" HorizontalOptions="Center" />
      </ViewCell>
    </DataTemplate>
   </ListView.ItemTemplate>
 </ListView>

然后是一些标签

 <Label Text="If you feel you're missing"
            FontSize="15"
            VerticalOptions="Center"
            HorizontalOptions="Center"
            TextColor="White"
            />
     <Label Text="a group or two, please contact"
               FontSize="15"
            VerticalOptions="Center"
            HorizontalOptions="Center"
            TextColor="White"
            />
     <Label Text="your manager"
             FontSize="15"
            VerticalOptions="Center"
            HorizontalOptions="Center"
            TextColor="White"
            />


     </StackLayout>

图像背景色

你可以尝试

HasUnevenRows = "true"

对于“禁用选择”,您可以按照以下步骤操作

禁用选择

SelectionDemoList.ItemSelected += (sender, e) => {
    ((ListView)sender).SelectedItem = null;
};

请注意,在Windows Phone上,包括SwitchCell在内的某些单元不会响应选择而更新其可视状态。

要降低ListView的高度,可以使用网格。 这是一个样本

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="TestRelativeLayout.MyPage2">
    <ContentPage.Content>
        <StackLayout>
                    <StackLayout>
                                        <Grid VerticalOptions = "FillAndExpand">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="50" />
                    <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="10*" />
                    <ColumnDefinition Width = "1*"/>
                    </Grid.ColumnDefinitions>
            <Entry Placeholder="MyEntry" Grid.Column = "0" Grid.Row="0" Grid.ColumnSpan = "2"/>
            <Image Source="icon.png" Grid.Column="1" Grid.Row = "0" Margin="0,0,20,0"/>
                </Grid>
        </StackLayout>
                                <Grid VerticalOptions = "FillAndExpand">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="150" />
                    <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                        <ListView x:Name="ListGroups" 
                    Grid.Row = "0"
                    Grid.Column = "0"
           ItemsSource="{Binding myList}" 
           HorizontalOptions="Center"
                VerticalOptions="Start"
                BackgroundColor = "Red">
   <ListView.ItemTemplate>
    <DataTemplate >
      <ViewCell>
             <Label Text="{Binding Name}" TextColor="Aqua" FontSize="10" HorizontalOptions="Center" />
      </ViewCell>
    </DataTemplate>
   </ListView.ItemTemplate>
 </ListView>
            <StackLayout Grid.Row = "1" Grid.Column = "0" >
            <Label Text="If you feel you're missing"
            FontSize="15"
            VerticalOptions="StartAndExpand"
            HorizontalOptions="Center"
            TextColor="Black"
            />
     <Label Text="a group or two, please contact"
               FontSize="15"
            VerticalOptions="StartAndExpand"
            HorizontalOptions="Center"
            TextColor="Black"
            />
     <Label Text="your manager"
             FontSize="15"
            VerticalOptions="StartAndExpand"
            HorizontalOptions="Center"
            TextColor="Black"
            />
            </StackLayout>
            </Grid>

        </StackLayout>
    </ContentPage.Content>
</ContentPage>

你有这个(在模拟器/ Android上)

样品

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM