Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Poor Performance when instantiating a custom ContentView with a simple layout

$
0
0

Xamarin Friends,
We have a StackLayout which we are adding 56 CustomViews containing a Grid which contains 6 Labels and 2 BoxViews. Each time we instantiate a new CustomView (called new CustomView()) it takes a little more than a second. So overall it takes about 2 minutes to load right now on an Galaxy S5.

NOTE: iPhone 6+ is faster
NOTE: Adding the created CustomView to the StackLayout is fast and not a problem

We have removed all the labels from the CustomView and the BoxViews and the creation is pretty instant. Adding back each Label and BoxView 1 by 1 slowed down the time it took to instantiate a new CustomView, but only a little. There is no single offending element.

We are considering whether or not we need to use a CustomRenderer at this point for an iOS and Android specific implementation of the CustomView in order to gain back performance.

Our custom ContentView

<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Namespace.Class"
             WidthRequest="168">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="2*" />
            <RowDefinition Height="2*" />
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="2*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Label Grid.Row="0"
               Grid.Column="0"
               Text="{Binding Value}"
               TextColor="White"
               BackgroundColor="Gray"
               VerticalOptions="CenterAndExpand"
               HorizontalOptions="CenterAndExpand"
               FontSize="Large"
               XAlign="Center" />
        <BoxView Grid.Row="0"
                 Grid.Column="1"
                 Color="Blue"
                 HorizontalOptions="Start"
                 VerticalOptions="Center"
                 HeightRequest="25" />
        <Label Grid.Row="0"
               Grid.Column="2"
               Text="{Binding Value}"
               TextColor="White"
               FontSize="Medium"
               BackgroundColor="Red"
               VerticalOptions="Center"
               HorizontalOptions="End"
               WidthRequest="25"
               HeightRequest="25"
               XAlign="Center"
               YAlign="Center" />
        <Label Grid.Row="1"
               Grid.Column="0"
               Text="{Binding Value}"
               VerticalOptions="Center"
               HorizontalOptions="Start" />
        <Label Grid.Row="1"
               Grid.Column="1"
               Text="{Binding Value}"
               VerticalOptions="Center"
               HorizontalOptions="Start" />
        <Label Grid.Row="2"
               Grid.Column="0"
               Grid.ColumnSpan="2"
               Text="{Binding Value}"
               VerticalOptions="Center"
               HorizontalOptions="Start" />
        <Label Grid.Row="3"
               Grid.Column="0"
               Grid.ColumnSpan="2"
               Text="{Binding Value}"
               VerticalOptions="Center"
               HorizontalOptions="Start" />
        <BoxView Grid.Row="3"
                 Grid.Column="2"
                 Color="Aqua"
                 HorizontalOptions="Center"
                 VerticalOptions="End" />
    </Grid>
</ContentView>

We really need help and guidance here. Thanks!

-Danny


Viewing all articles
Browse latest Browse all 58056

Trending Articles