Forum General

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Changing StackLayout/Listview Height?

bear42bear42 Member ✭✭

I have a listview whose height seems to be changing. It's bee reported on iOS, and we aren't sure about Android.
This is what it normally should look like:

Occasionally, after being in the app, it can look like this:

here is the XAML for that form:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Name="currentPage"
             xmlns:local="clr-namespace:BreezeMobile.View"
             NavigationPage.HasNavigationBar="False"
             x:Class="BreezeMobile.View.FyiView">
    <ContentPage.Content>

        <StackLayout BackgroundColor="{DynamicResource MainBackground}">

            <Label>
                <Label.HeightRequest>

                    <OnPlatform x:TypeArguments="x:Double"
                                    iOS="50"
                                    Android="30"
                        />
                </Label.HeightRequest>


            </Label>

            <StackLayout BackgroundColor="{DynamicResource MainBackground}" HorizontalOptions="Fill" Orientation="Horizontal">

                <StackLayout HorizontalOptions="Start">

                    <StackLayout.GestureRecognizers>

                        <TapGestureRecognizer 
                                            Tapped="NavToMainMenu" 
                                            NumberOfTapsRequired="1"/>

                    </StackLayout.GestureRecognizers>

                    <Button WidthRequest="85" Text="&lt; back" Margin="0,-15,0,0" TextColor="{DynamicResource FontForeColor}"  HeightRequest="50" Clicked="NavToMainMenu" FontSize="16" BackgroundColor="{DynamicResource MainBackground}">

                    </Button>

                </StackLayout>

                <StackLayout HorizontalOptions="CenterAndExpand">
                    <StackLayout.GestureRecognizers>

                        <TapGestureRecognizer 
                                            Tapped="NavToMainMenu" 
                                            NumberOfTapsRequired="1"/>

                    </StackLayout.GestureRecognizers>

                    <Label HorizontalOptions="Center" Text="my time" TextColor="White" />
                    <Label Text="tap category for details" HorizontalOptions="Center" TextColor="{DynamicResource FontForeColor}" />
                </StackLayout>
                <StackLayout HorizontalOptions="EndAndExpand">
                    <StackLayout.GestureRecognizers>

                        <TapGestureRecognizer 
                                            Tapped="TapNavSettings" 
                                            NumberOfTapsRequired="1"/>

                    </StackLayout.GestureRecognizers>
                    <Image WidthRequest="30" Margin="0,-5,0,0" HeightRequest="30" Source="{DynamicResource Gear}" />
                </StackLayout>
                <Label Text="xx" TextColor="{DynamicResource TransparentColor}"/>
            </StackLayout>

            <StackLayout x:Name="hotelStack" Padding="1,0,1,0" VerticalOptions="FillAndExpand">
             <StackLayout.HeightRequest>
                    <OnPlatform x:TypeArguments="x:Double"
                                  iOS     ="790"
                                  Android ="650"
                                  />

                </StackLayout.HeightRequest>
                <AbsoluteLayout>
                    <ListView
                    x:Name="HotelsList"
                    BackgroundColor="White"
                    IsGroupingEnabled="True"
                    IsPullToRefreshEnabled="true"
                    IsRefreshing="{Binding IsBusy, Mode=OneWay}"
                    ItemsSource="{Binding Items}"
                    RefreshCommand="{Binding LoadFyiCommand}"
                    HasUnevenRows="True"
                    AbsoluteLayout.LayoutFlags="All"
                    AbsoluteLayout.LayoutBounds="0,0,1,1"
                    SeparatorVisibility="None"
                    >
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <ViewCell Height="68">
                                    <AbsoluteLayout>
                                        <Frame AbsoluteLayout.LayoutBounds="13,2" HeightRequest ="25" WidthRequest ="25" HasShadow="False" BorderColor="LightGray" BackgroundColor="#F6F7FB" CornerRadius="10"/>
                                        <Label FontSize="14" FontFamily="Verdana" WidthRequest="50" HorizontalTextAlignment="Center" AbsoluteLayout.LayoutBounds="21,3" HorizontalOptions="Start" Text="{Binding MonthAbbr}" TextColor="#6F7982"/>
                                        <Label FontSize="30" FontFamily="Verdana" WidthRequest="50" HorizontalTextAlignment="Center" AbsoluteLayout.LayoutBounds="21,15" HorizontalOptions="Start" Text="{Binding Day}" TextColor="Black"/>
                                        <Label FontSize="14" FontFamily="Verdana" WidthRequest="50" HorizontalTextAlignment="Center" AbsoluteLayout.LayoutBounds="21,48" HorizontalOptions="Start" Text="{Binding DayOfWeek}" TextColor="#6F7982"/>

                                        <Label FontSize="18" FontFamily="Verdana" WidthRequest="150" HorizontalTextAlignment="Start" AbsoluteLayout.LayoutBounds="83,12" HorizontalOptions="Start" Text="{Binding CatName}" TextColor="Black"/>
                                        <Label FontSize="12" FontFamily="Verdana" WidthRequest="100" HorizontalTextAlignment="Start" AbsoluteLayout.LayoutBounds="83,35" HorizontalOptions="Start" Text="{Binding Display}" TextColor="Black"/>
                                    </AbsoluteLayout>
                                </ViewCell>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                        <ListView.GroupHeaderTemplate>
                            <DataTemplate>
                                <ViewCell Height="90">
                                    <AbsoluteLayout BackgroundColor="White">
                                        <Frame AbsoluteLayout.LayoutBounds="15,21" HeightRequest="24" WidthRequest="120" CornerRadius="10" HasShadow="False" BorderColor="White" BackgroundColor="White">
                                            <Frame.GestureRecognizers>
                                                <TapGestureRecognizer Command="{Binding Source={x:Reference currentPage}, Path=BindingContext.RefreshItemsCommand}"  NumberOfTapsRequired="1" CommandParameter="{Binding .}"/>
                                            </Frame.GestureRecognizers>
                                        </Frame>
                                        <!-- Main Title-->
                                        <Label FontSize="18" FontFamily="Verdana" AbsoluteLayout.LayoutBounds="25,20" HeightRequest="100" WidthRequest="500" HorizontalOptions="Start" Text="{Binding CatDesc}" TextColor="Black">
                                            <Label.GestureRecognizers>
                                                <TapGestureRecognizer Command="{Binding Source={x:Reference currentPage}, Path=BindingContext.RefreshItemsCommand}"  NumberOfTapsRequired="1" CommandParameter="{Binding .}"/>
                                            </Label.GestureRecognizers>
                                        </Label>
                                        <!-- Ellipsis-->
                                        <Label FontSize="18" FontFamily="Verdana" WidthRequest="50" HorizontalTextAlignment="Center" AbsoluteLayout.LayoutBounds="320,15" HorizontalOptions="Start" Text="..." TextColor="Black" IsVisible="{Binding HasDays}">
                                            <Label.GestureRecognizers>
                                                <TapGestureRecognizer Command="{Binding Source={x:Reference currentPage}, Path=BindingContext.RefreshItemsCommand}"  NumberOfTapsRequired="1" CommandParameter="{Binding .}"/>
                                            </Label.GestureRecognizers>
                                        </Label>
                                        <!-- Allowed Label-->
                                        <Label FontSize="12" FontFamily="Verdana" WidthRequest="50" HorizontalTextAlignment="Center" AbsoluteLayout.LayoutBounds="22,41" HorizontalOptions="Start" Text="allowed" TextColor="Gray" IsVisible="{Binding IsAllowed}">
                                            <Label.GestureRecognizers>
                                                <TapGestureRecognizer Command="{Binding Source={x:Reference currentPage}, Path=BindingContext.RefreshItemsCommand}"  NumberOfTapsRequired="1" CommandParameter="{Binding .}"/>
                                            </Label.GestureRecognizers>
                                        </Label>
                                        <!-- Allowed Value-->
                                        <Label FontSize="16" FontFamily="Verdana" WidthRequest="50" HorizontalTextAlignment="End" AbsoluteLayout.LayoutBounds="20,54" HorizontalOptions="Start" Text="{Binding CatAllowed}" TextColor="Black" IsVisible="{Binding IsAllowed}">
                                            <Label.GestureRecognizers>
                                                <TapGestureRecognizer Command="{Binding Source={x:Reference currentPage}, Path=BindingContext.RefreshItemsCommand}"  NumberOfTapsRequired="1" CommandParameter="{Binding .}"/>
                                            </Label.GestureRecognizers>
                                        </Label>
                                        <!-- Used Label Not Allowed-->
                                        <Label FontSize="12" FontFamily="Verdana" WidthRequest="50" HorizontalTextAlignment="Center" AbsoluteLayout.LayoutBounds="15,41" HorizontalOptions="Start" Text="used" TextColor="Gray" IsVisible="{Binding IsNotAllowed}">
                                            <Label.GestureRecognizers>
                                                <TapGestureRecognizer Command="{Binding Source={x:Reference currentPage}, Path=BindingContext.RefreshItemsCommand}"  NumberOfTapsRequired="1" CommandParameter="{Binding .}"/>
                                            </Label.GestureRecognizers>
                                        </Label>
                                        <!-- Used Value Not Allowed-->
                                        <Label FontSize="16" FontFamily="Verdana" WidthRequest="50" HorizontalTextAlignment="End" AbsoluteLayout.LayoutBounds="20,54" HorizontalOptions="Start" Text="{Binding CatRecorded}" TextColor="Black" IsVisible="{Binding IsNotAllowed}">
                                            <Label.GestureRecognizers>
                                                <TapGestureRecognizer Command="{Binding Source={x:Reference currentPage}, Path=BindingContext.RefreshItemsCommand}"  NumberOfTapsRequired="1" CommandParameter="{Binding .}"/>
                                            </Label.GestureRecognizers>
                                        </Label>
                                        <!-- Used Label Allowed-->
                                        <Label FontSize="12" FontFamily="Verdana" WidthRequest="50" HorizontalTextAlignment="Center" AbsoluteLayout.LayoutBounds="157,41" HorizontalOptions="Start" Text="used" TextColor="Gray" IsVisible="{Binding IsAllowed}">
                                            <Label.GestureRecognizers>
                                                <TapGestureRecognizer Command="{Binding Source={x:Reference currentPage}, Path=BindingContext.RefreshItemsCommand}"  NumberOfTapsRequired="1" CommandParameter="{Binding .}"/>
                                            </Label.GestureRecognizers>
                                        </Label>
                                        <!-- Used Value Allowed-->
                                        <Label FontSize="16" FontFamily="Verdana" WidthRequest="50" HorizontalTextAlignment="End" AbsoluteLayout.LayoutBounds="156,54" HorizontalOptions="Start" Text="{Binding CatRecorded}" TextColor="Black" IsVisible="{Binding IsAllowed}">
                                            <Label.GestureRecognizers>
                                                <TapGestureRecognizer Command="{Binding Source={x:Reference currentPage}, Path=BindingContext.RefreshItemsCommand}"  NumberOfTapsRequired="1" CommandParameter="{Binding .}"/>
                                            </Label.GestureRecognizers>
                                        </Label>
                                        <!-- Remaining Label-->
                                        <Label FontSize="12" FontFamily="Verdana" WidthRequest="70" HorizontalTextAlignment="Center" AbsoluteLayout.LayoutBounds="290,41" HorizontalOptions="Start" Text="remaining" TextColor="Gray" IsVisible="{Binding IsAllowed}">
                                            <Label.GestureRecognizers>
                                                <TapGestureRecognizer Command="{Binding Source={x:Reference currentPage}, Path=BindingContext.RefreshItemsCommand}"  NumberOfTapsRequired="1" CommandParameter="{Binding .}"/>
                                            </Label.GestureRecognizers>
                                        </Label>
                                        <!-- Remaining Value-->
                                        <Label FontSize="16" FontFamily="Verdana" WidthRequest="50" HorizontalTextAlignment="End" AbsoluteLayout.LayoutBounds="305,54" HorizontalOptions="Start" Text="{Binding CatRemaining}" TextColor="Black" IsVisible="{Binding IsAllowed}">
                                            <Label.GestureRecognizers>
                                                <TapGestureRecognizer Command="{Binding Source={x:Reference currentPage}, Path=BindingContext.RefreshItemsCommand}"  NumberOfTapsRequired="1" CommandParameter="{Binding .}"/>
                                            </Label.GestureRecognizers>
                                        </Label>
                                        <!-- Color Bar-->
                                        <BoxView AbsoluteLayout.LayoutBounds="23,78" CornerRadius="5" HeightRequest="5" WidthRequest="332" BackgroundColor="{Binding CatColor}">
                                            <BoxView.GestureRecognizers>
                                                <TapGestureRecognizer Command="{Binding Source={x:Reference currentPage}, Path=BindingContext.RefreshItemsCommand}"  NumberOfTapsRequired="1" CommandParameter="{Binding .}"/>
                                            </BoxView.GestureRecognizers>
                                        </BoxView>
                                        <!-- Separator Bar - iOs has a problem with this so we are rolling our own here-->
                                        <!--<BoxView AbsoluteLayout.LayoutBounds="1,104" HeightRequest="1" WidthRequest="410" BackgroundColor="Gray"/>-->
                                    </AbsoluteLayout>
                                </ViewCell>
                            </DataTemplate>
                        </ListView.GroupHeaderTemplate>
                    </ListView>
                    <ActivityIndicator x:Name="activity"  
                       IsRunning="{Binding Path=IsBusy, Source={x:Reference currentPage}}"
                       IsEnabled="False"  
                       IsVisible="False"  
                       Color="Blue"  
                       BackgroundColor="Transparent"
                       AbsoluteLayout.LayoutFlags="PositionProportional"
                       AbsoluteLayout.LayoutBounds=".5,.5,-1,-1"/>
                </AbsoluteLayout>
            </StackLayout>

            <StackLayout Orientation="Horizontal" VerticalOptions="EndAndExpand" HorizontalOptions="Fill">

                <Label HeightRequest="3" Text="x" TextColor="{DynamicResource TransparentColor}" />

                <StackLayout HorizontalOptions="Start" BackgroundColor="{DynamicResource MainBackground}" WidthRequest="100">
                    <StackLayout.GestureRecognizers>

                        <TapGestureRecognizer 
                                            Tapped="NavToMainMenu" 
                                            NumberOfTapsRequired="1"/>

                    </StackLayout.GestureRecognizers>

                    <Image BackgroundColor="{DynamicResource MainBackground}" HorizontalOptions="Start" Source="{DynamicResource Home}" WidthRequest="50" HeightRequest="30" />


                </StackLayout>

                <StackLayout HorizontalOptions="CenterAndExpand" BackgroundColor="{DynamicResource MainBackground}">

                    <Label HeightRequest="3" Text="x" TextColor="{DynamicResource TransparentColor}" />

                </StackLayout>

                <StackLayout Orientation="Horizontal" BackgroundColor="{DynamicResource MainBackground}" WidthRequest="100">
                    <StackLayout.GestureRecognizers>

                        <TapGestureRecognizer 
                                            Tapped="TapNavSignOut" 
                                            NumberOfTapsRequired="1"/>

                    </StackLayout.GestureRecognizers>

                    <Image Source="{DynamicResource SignOut}" HorizontalOptions="EndAndExpand" />

                    <Label HeightRequest="3" Text="x" TextColor="{DynamicResource TransparentColor}" />

                </StackLayout>


            </StackLayout>
            <Label HeightRequest="3" Text="x" TextColor="{DynamicResource TransparentColor}" />

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

the place where I'm setting the height of the StackLayout/Listview is here:

<StackLayout.HeightRequest>
                        <OnPlatform x:TypeArguments="x:Double"
                                      iOS     ="790"
                                      Android ="650"
                                      />

</StackLayout.HeightRequest>

Any ideas why the height might change like that?

Sign In or Register to comment.