Skip to content

ListView items still reserve space even if collapsed on Android #1099

Closed as not planned

Description

@peternary

Current behavior

If ItemContainerStyle has a MinHeight of 0 and the ItemTemplate contains a Grid for which the Visibility is set to Collapsed then the space for that row is still reserved on Android. Works in UWP/WASM

Expected behavior

Space for rows should not be reserved.

How to reproduce it (as minimally and precisely as possible)

AndroidListviewHiding.zip

Open the attached project in Android and observe that space for all rows is reserved. In UWP these rows have no space assigned.

Environment

Nuget Package:
Uno.UI
Package Version(s):
1.45.0-dev.1852
Affected platform(s):

  • iOS
  • Android
  • WebAssembly
  • Windows
  • Build tasks

Visual Studio

  • 2017 (version: )
  • 2019 (version: )
  • for Mac (version: )

Relevant plugins

  • Resharper (version: )

Anything else we need to know?

Activity

  1. added
    platform/android 🤖
    kind/bug
    on Jun 20, 2019
  2. davidjohnoliver commented on Jun 26, 2019

    @davidjohnoliver
    Contributor

    The difference from UWP is because Uno is not using the same default ListViewItem style. Uno is using the ListViewItemExpanded style which contains invisible elements (to support scenarios like multi-selection and data virtualization) that still take up space when the content is collapsed.

    As a workaround, you can use the following Style, with the invisible items removed from the template:

    <ListView.ItemContainerStyle>
    	<Style TargetType="ListViewItem">
    		<Setter Property="Padding"
    				Value="0" />
    		<Setter Property="BorderThickness"
    				Value="0" />
    		<Setter Property="HorizontalContentAlignment"
    				Value="Stretch" />
    		<Setter Property="MinHeight"
    				Value="0" />
    		<Setter Property="Template">
    			<Setter.Value>
    				<ControlTemplate TargetType="ListViewItem">
    					<Grid x:Name="ContentBorder"
    							Background="{TemplateBinding Background}"
    							BorderBrush="{TemplateBinding BorderBrush}"
    							BorderThickness="{TemplateBinding BorderThickness}">
    						<VisualStateManager.VisualStateGroups>
    							<VisualStateGroup x:Name="CommonStates">
    								<VisualState x:Name="Normal">
    									<Storyboard>
    										<win:PointerUpThemeAnimation Storyboard.TargetName="ContentPresenter" />
    									</Storyboard>
    								</VisualState>
    								<VisualState x:Name="PointerOver">
    									<Storyboard>
    										<DoubleAnimation Storyboard.TargetName="BorderBackground"
    															Storyboard.TargetProperty="Opacity"
    															Duration="0"
    															To="1" />
    										<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderBackground"
    																		Storyboard.TargetProperty="Fill">
    											<DiscreteObjectKeyFrame KeyTime="0"
    																	Value="{ThemeResource SystemControlHighlightListLowBrush}" />
    										</ObjectAnimationUsingKeyFrames>
    										<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
    																		Storyboard.TargetProperty="Foreground">
    											<DiscreteObjectKeyFrame KeyTime="0"
    																	Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
    										</ObjectAnimationUsingKeyFrames>
    										<win:PointerUpThemeAnimation Storyboard.TargetName="ContentPresenter" />
    									</Storyboard>
    								</VisualState>
    								<VisualState x:Name="Pressed">
    									<Storyboard>
    										<DoubleAnimation Storyboard.TargetName="BorderBackground"
    															Storyboard.TargetProperty="Opacity"
    															Duration="0"
    															To="1" />
    										<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderBackground"
    																		Storyboard.TargetProperty="Fill">
    											<DiscreteObjectKeyFrame KeyTime="0"
    																	Value="{ThemeResource SystemControlHighlightListMediumBrush}" />
    										</ObjectAnimationUsingKeyFrames>
    										<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
    																		Storyboard.TargetProperty="Foreground">
    											<DiscreteObjectKeyFrame KeyTime="0"
    																	Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
    										</ObjectAnimationUsingKeyFrames>
    										<win:PointerDownThemeAnimation TargetName="ContentPresenter" />
    									</Storyboard>
    								</VisualState>
    								<VisualState x:Name="Selected">
    									<Storyboard>
    										<DoubleAnimation Storyboard.TargetName="BorderBackground"
    															Storyboard.TargetProperty="Opacity"
    															Duration="0"
    															To="1" />
    										<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderBackground"
    																		Storyboard.TargetProperty="Fill">
    											<DiscreteObjectKeyFrame KeyTime="0"
    																	Value="{ThemeResource SystemControlHighlightListAccentLowBrush}" />
    										</ObjectAnimationUsingKeyFrames>
    										<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
    																		Storyboard.TargetProperty="Foreground">
    											<DiscreteObjectKeyFrame KeyTime="0"
    																	Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
    										</ObjectAnimationUsingKeyFrames>
    										<win:PointerUpThemeAnimation Storyboard.TargetName="ContentPresenter" />
    									</Storyboard>
    								</VisualState>
    								<VisualState x:Name="PointerOverSelected">
    									<Storyboard>
    										<DoubleAnimation Storyboard.TargetName="BorderBackground"
    															Storyboard.TargetProperty="Opacity"
    															Duration="0"
    															To="1" />
    										<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderBackground"
    																		Storyboard.TargetProperty="Fill">
    											<DiscreteObjectKeyFrame KeyTime="0"
    																	Value="{ThemeResource SystemControlHighlightListAccentMediumBrush}" />
    										</ObjectAnimationUsingKeyFrames>
    										<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
    																		Storyboard.TargetProperty="Foreground">
    											<DiscreteObjectKeyFrame KeyTime="0"
    																	Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
    										</ObjectAnimationUsingKeyFrames>
    										<win:PointerUpThemeAnimation Storyboard.TargetName="ContentPresenter" />
    									</Storyboard>
    								</VisualState>
    								<VisualState x:Name="PressedSelected">
    									<Storyboard>
    										<DoubleAnimation Storyboard.TargetName="BorderBackground"
    															Storyboard.TargetProperty="Opacity"
    															Duration="0"
    															To="1" />
    										<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderBackground"
    																		Storyboard.TargetProperty="Fill">
    											<DiscreteObjectKeyFrame KeyTime="0"
    																	Value="{ThemeResource SystemControlHighlightListAccentHighBrush}" />
    										</ObjectAnimationUsingKeyFrames>
    										<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
    																		Storyboard.TargetProperty="Foreground">
    											<DiscreteObjectKeyFrame KeyTime="0"
    																	Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
    										</ObjectAnimationUsingKeyFrames>
    										<win:PointerDownThemeAnimation TargetName="ContentPresenter" />
    									</Storyboard>
    								</VisualState>
    							</VisualStateGroup>
    							<VisualStateGroup x:Name="DisabledStates">
    								<VisualState x:Name="Enabled" />
    								<VisualState x:Name="Disabled">
    									<Storyboard>
    										<DoubleAnimation Storyboard.TargetName="ContentBorder"
    															Storyboard.TargetProperty="Opacity"
    															Duration="0"
    															To="{ThemeResource ListViewItemDisabledThemeOpacity}" />
    									</Storyboard>
    								</VisualState>
    							</VisualStateGroup>
    							<VisualStateGroup x:Name="ReorderHintStates">
    								<VisualState x:Name="NoReorderHint" />
    								<VisualState x:Name="BottomReorderHint">
    									<Storyboard>
    										<win:DragOverThemeAnimation TargetName="ContentBorder"
    																	ToOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
    																	Direction="Bottom" />
    									</Storyboard>
    								</VisualState>
    								<VisualState x:Name="TopReorderHint">
    									<Storyboard>
    										<win:DragOverThemeAnimation TargetName="ContentBorder"
    																	ToOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
    																	Direction="Top" />
    									</Storyboard>
    								</VisualState>
    								<VisualState x:Name="RightReorderHint">
    									<Storyboard>
    										<win:DragOverThemeAnimation TargetName="ContentBorder"
    																	ToOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
    																	Direction="Right" />
    									</Storyboard>
    								</VisualState>
    								<VisualState x:Name="LeftReorderHint">
    									<Storyboard>
    										<win:DragOverThemeAnimation TargetName="ContentBorder"
    																	ToOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
    																	Direction="Left" />
    									</Storyboard>
    								</VisualState>
    								<VisualStateGroup.Transitions>
    									<VisualTransition To="NoReorderHint"
    														GeneratedDuration="0:0:0.2" />
    								</VisualStateGroup.Transitions>
    							</VisualStateGroup>
    							<VisualStateGroup x:Name="DragStates">
    								<VisualState x:Name="NotDragging" />
    								<VisualState x:Name="Dragging">
    									<Storyboard>
    										<DoubleAnimation Storyboard.TargetName="ContentBorder"
    															Storyboard.TargetProperty="Opacity"
    															Duration="0"
    															To="{ThemeResource ListViewItemDragThemeOpacity}" />
    										<win:DragItemThemeAnimation TargetName="ContentBorder" />
    									</Storyboard>
    								</VisualState>
    								<VisualState x:Name="DraggingTarget">
    									<Storyboard>
    										<win:DropTargetItemThemeAnimation TargetName="ContentBorder" />
    									</Storyboard>
    								</VisualState>
    								<VisualState x:Name="DraggedPlaceholder">
    									<Storyboard>
    										<win:FadeOutThemeAnimation TargetName="ContentBorder" />
    									</Storyboard>
    								</VisualState>
    								<VisualStateGroup.Transitions>
    									<VisualTransition To="NotDragging"
    														GeneratedDuration="0:0:0.2" />
    								</VisualStateGroup.Transitions>
    							</VisualStateGroup>
    						</VisualStateManager.VisualStateGroups>
    						<Rectangle x:Name="BorderBackground"
    									IsHitTestVisible="False"
    									Fill="{ThemeResource SystemControlHighlightListAccentLowBrush}"
    									Opacity="0"
    									Control.IsTemplateFocusTarget="True" />
    						<Grid x:Name="ContentPresenterGrid"
    								Background="Transparent"
    								Margin="0,0,0,0">
    							<Grid.RenderTransform>
    								<TranslateTransform x:Name="ContentPresenterTranslateTransform" />
    							</Grid.RenderTransform>
    							<ContentPresenter x:Name="ContentPresenter"
    												ContentTransitions="{TemplateBinding ContentTransitions}"
    												ContentTemplate="{TemplateBinding ContentTemplate}"
    												xamarin:ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
    												Content="{TemplateBinding Content}"
    												HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
    												VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
    												Margin="{TemplateBinding Padding}" />
    						</Grid>
    					</Grid>
    				</ControlTemplate>
    			</Setter.Value>
    		</Setter>
    	</Style>
    </ListView.ItemContainerStyle>

    In order to support the correct default style, we should implement the properties of ListViewItemPresenter.

  3. pkar70 commented on Feb 2, 2020

    @pkar70
    Contributor

    Still no change? :(

  4. added
    project/items 🧾
    and removed on Sep 21, 2020
  5. added
    difficulty/tbd
    on Feb 15, 2021
  6. added
    difficulty/medium 🤔
    and removed
    difficulty/tbd
    on May 31, 2021
  7. MartinZikmund commented on Jul 15, 2025

    @MartinZikmund
    Member

    Only relevant to native renderer, closing.

  8. github-actions commented on May 5, 2026

    @github-actions
    Contributor

    This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or feature requests.

  9. locked as resolved and limited conversation to collaborators on May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty/medium 🤔kind/bugplatform/android 🤖project/items 🧾

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions