Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

any way to improve image performance in listview, without native renderers?

GeorgeCookGeorgeCook PEUniversity ✭✭✭

For xamarin forms to be super useful, I would expect the follwing code to be fast..

    <ListView.ItemTemplate>
            <DataTemplate>

                <ViewCell Height="300"> 
                    <AbsoluteLayout> 
                        <Image AbsoluteLayout.LayoutFlags="WidthProportional" AbsoluteLayout.LayoutBounds="0,0,1,240"
                            Source="{Binding ImageSource}" 
                            Aspect="AspectFill"/>

                        <Image AbsoluteLayout.LayoutFlags="None" AbsoluteLayout.LayoutBounds="5,245,40,40"
                            Source="{Binding UserThumbnailImageSource}" 
                            Aspect="AspectFill"/>


                        <Label AbsoluteLayout.LayoutFlags="WidthProportional" AbsoluteLayout.LayoutBounds="50,245,AutoSize,20"
                            Text="{Binding Username}" 
                            FontAttributes="Bold"
                            FontSize="Small" 
                            TextColor="Black" 
                            LineBreakMode="TailTruncation"/>
                        <Label AbsoluteLayout.LayoutFlags="WidthProportional" AbsoluteLayout.LayoutBounds="50,270,AutoSize,40"
                            Text="{Binding Description}" 
                            FontSize="Small" 
                            TextColor="Black" 
                            LineBreakMode="TailTruncation"/>

                    </AbsoluteLayout>
                </ViewCell> 
            </DataTemplate>
        </ListView.ItemTemplate>

as it is, it looks like I'll have to make custom renders natively as this jitters to hell on my iphone 6.

am I doing this wrong? is there a way to get better performance for this use case, without needing to drop down and optimize?

Best Answer

Answers

  • OtaMaresOtaMares DEMember ✭✭

    @rogihee do you have an example on how to only override the OnSizeRequest method and what logic it should contain to improve performance?

  • rogiheerogihee NLMember ✭✭✭

    I'm still struggling with this too, investigating still where exactly the performance issues are. My labels are updated frequently in my app (every second) and AFAICT every myLabel.Text = "..." will trigger a complete layout cycle (correct me if I'm wrong). With 20+ labels and 40+ images on 1 screen that creates noticeable lag.

    I'm trying to find a way to prevent that from happening, because most of the time a complete layout cycle is not needed for labels, they have "fixed" sizes. Or do a batch update of all the labels and then call Layout. Right now, 10 of 20 labels are updated every second creating 10 layout cycles within 0.01 seconds...

    Not sure yet if it is the Label size calculation itself or the amount of layout cycles called.

Sign In or Register to comment.