gpt4 book ai didi

c# - Xamarin.forms 如何滚动使用 AbsoluteLayout

转载 作者:行者123 更新时间:2023-11-30 20:27:10 29 4
gpt4 key购买 nike

我有这个 .XAML 页面,但 Scroll 不起作用当我删除 AbsoluteLayout 并采用 stacklayout 时,它工作正常。

<ScrollView>
<AbsoluteLayout>
<ListView x:Name="lstView" ItemsSource="{Binding Items}" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1"
ItemSelected="lstView_ItemSelected">

<ListView.Header>
<Label Text="Store Allocation" BackgroundColor="White" TextColor="Black" FontAttributes="Bold" HorizontalOptions="Fill" HorizontalTextAlignment="Center" />

</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Title}" Height="200" Detail="{Binding Detail}" DetailColor="Black" TextColor="Red" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<BoxView AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1" BackgroundColor="LightGray" Opacity="0.7" InputTransparent="False" IsVisible="{Binding Path=IsBusy, Source={x:Reference Page}}" />
<ActivityIndicator IsRunning="{Binding Path=IsBusy, Source={x:Reference Page}}" AbsoluteLayout.LayoutFlags="PositionProportional" AbsoluteLayout.LayoutBounds=".5,.5,-1,-1" />
</AbsoluteLayout>
</ScrollView>

最佳答案

您的 XAML 基本上“说”在页面上放置一个 ScrollView,并用一个 AbsoluteLayout 填充该 ScrollView .由于内部布局完全适合 ScrollView,因此无需滚动。此外 ListViewBoxView 被设置为占用整个 AbsoluteLayout (AbsoluteLayout.LAyoutBounds="0,0,1,1 "), 不多也不少。为什么应该 ScrollView 滚动?

此外,如果它以这种方式工作,您将滚动 ActivityIndi​​cator 和其他所有内容,这可能不是您想要的。我假设您希望将 ActivityIndi​​cator 保留在 ListView 之上。

您可以尝试(我不是 100% 确定,但它应该有效)是仅使用 ScrollView 包装 ListView 并将 ScrollView AbsoluteLayout 中这样,ScrollView 将识别 ListView 对于屏幕来说太大并启用滚动,而其他所有内容留在原地:

<AbsoluteLayout>
<ScrollView AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
<ListView x:Name="lstView" ItemsSource="{Binding Items}"
ItemSelected="lstView_ItemSelected">
<ListView.Header>
<Label Text="Store Allocation" BackgroundColor="White" TextColor="Black" FontAttributes="Bold" HorizontalOptions="Fill" HorizontalTextAlignment="Center" />
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Title}" Height="200" Detail="{Binding Detail}" DetailColor="Black" TextColor="Red" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollView>
<BoxView AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1" BackgroundColor="LightGray" Opacity="0.7" InputTransparent="False" IsVisible="{Binding Path=IsBusy, Source={x:Reference Page}}" />
<ActivityIndicator IsRunning="{Binding Path=IsBusy, Source={x:Reference Page}}" AbsoluteLayout.LayoutFlags="PositionProportional" AbsoluteLayout.LayoutBounds=".5,.5,-1,-1" />
</AbsoluteLayout>

关于c# - Xamarin.forms 如何滚动使用 AbsoluteLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49002423/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com