C# 如何使用AbsoluteLayout滚动Xamarin.forms

C# 如何使用AbsoluteLayout滚动Xamarin.forms,c#,xamarin,xamarin.forms,C#,Xamarin,Xamarin.forms,我有这个.XAML页面和滚动条不工作 当我删除AbsoluteLayout并使用stacklayout时,工作正常 <ScrollView> <AbsoluteLayout> <ListView x:Name="lstView" ItemsSource="{Binding Items}" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1"

我有这个.XAML页面和滚动条不工作 当我删除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基本上是“在页面上放置一个
滚动视图
,并用
绝对布局
填充
滚动视图
。由于内部布局完全适合
滚动视图
,因此无需滚动。此外,
ListView
BoxView
设置为获取整个
AbsoluteLayout
AbsoluteLayout.layoutbunds=“0,0,1,1”
),不多不少。为什么
滚动视图
要滚动

此外,如果它是这样工作的,那么您可以滚动
活动指示器
和其他所有内容,这可能不是您想要的。我假设您希望在
列表视图
的顶部保留
活动指示器

您可以尝试的是(我不是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>

您还可以手动设置AbsoluteLayout的高度

<ScrollView>
<AbsoluteLayout HeightRequest="800">
      <!--Page Contents-->
</AbsoluteLayout>
</ScrollView>


我想覆盖加载视图,请看一看:我知道。我是回答你另一个问题的人。这里给出的答案的确切问题是什么?我没有删除
ActivityIndicator
覆盖,我只是将
ScrollView
向下移动了层次结构,它直接包装
列表视图
,而不是整个
AbsoluteLayout
,由于我在回答中给出的原因,它不起作用。问题是,当我在scrollView下使用AbsoluteLayout时,scrollView不起作用。这正是我所说的。因此,我告诉过你把
滚动视图
放在
绝对布局
中,而不是相反。明白了!谢谢你的帮助