Xamarin.Forms - How to overlay an ActivityIndicator in the middle of a StackLayout programmatically

前端 未结 7 1759
谎友^
谎友^ 2020-12-13 06:59

I want to overlay my ActivityIndicator in the middle of my form but I\'m not entirely sure how I can go about this, I assume I need to wrap my stack layout in a relative lay

相关标签:
7条回答
  • 2020-12-13 07:40

    You need to use absolute layout. Follow the following hierarchy of the layout:

    <AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
        <StackLayout AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
    
            <!--< Your control design goes here >-->
    
        </StackLayout>
    
        <StackLayout IsVisible="{Binding IsBusy}" Padding="12"
                 AbsoluteLayout.LayoutFlags="PositionProportional"
                 AbsoluteLayout.LayoutBounds="0.5,0.5,-1,-1">
    
            <ActivityIndicator IsRunning="{Binding IsBusy}" Color ="#80000000"/>
    
            <Label Text="Loading..." HorizontalOptions="Center" TextColor="White"/>
    
        </StackLayout>
    
    </AbsoluteLayout>
    

    With this the activity indicator will be overlaid in the middle of a stack layout.

    0 讨论(0)
提交回复
热议问题