ListView: Why do the separators have padding at the left but not at the right?

(Question is in the title.) At first, I thought there was something I was doing wrong but I've seen this same behavior in multiple "sample" projects at which I've looked. It just seems odd that the ListView behaves this way but there may be a good reason for it. I've tried using Margin on the ListView and the enclosing ScrollView without successfully affecting this. My solution uses RelativeLayout and constrains the ScrollView right and lower borders to the needed reduction. But this seems wrong and seems there should be a relative means of doing this. 'Course, really seems I shouldn't have to do this at all.

I've shared the main XAML below. Maybe someone will see something I missed.

<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:DeveloperForceDemo"
    x:Class="DeveloperForceDemo.MainPage">
    <ContentPage.Padding>
        <OnPlatform x:TypeArguments="Thickness" iOS="0, 20, 0, 0" Android="0, 0, 0, 0" />
    </ContentPage.Padding>
    <RelativeLayout BackgroundColor="Red">
        <StackLayout Orientation="Horizontal" BackgroundColor="Aqua" >
            <Button Command="{Binding AccountsCommand}" Text="Accounts" IsEnabled="{Binding IsAuthorized}" WidthRequest="100" />
            <Label Text="Count" FontAttributes="Bold" VerticalTextAlignment="Center"/>
            <Label Text="{Binding Accounts.Count}" VerticalTextAlignment="Center" />
        </StackLayout>
        <ScrollView
            RelativeLayout.YConstraint="44"
            RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Constant=-54}"
            RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Constant=-10}" >
            <ListView ItemsSource="{Binding Accounts}"
                BackgroundColor="Silver" >
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <TextCell Text="{Binding Name}" Detail="{Binding Id}" />
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </ScrollView>
        <ActivityIndicator
            IsVisible="{Binding IsBusy}"
            IsRunning="{Binding IsBusy}"
            Color="Black"
            VerticalOptions="CenterAndExpand"
            HorizontalOptions="CenterAndExpand"
            Scale="3"
            RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.5}"
            RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.5}" />
    </RelativeLayout>
</ContentPage>

Posts

  • CharwakaCharwaka INMember ✭✭✭✭✭
    edited December 2018

    From Xamarin Forms 3.4 you can use following code

    <ContentPage ...
                 xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core">
        <StackLayout Margin="20">
            <ListView ... ios:ListView.SeparatorStyle="FullWidth">
                ...
            </ListView>
        </StackLayout>
    </ContentPage>
    
Sign In or Register to comment.