Xamarin Forms : How to fix Activity Indicator in Centre of Screen in Scrollview

巧了我就是萌 提交于 2021-01-27 07:01:39

问题


I have a ScrollView over AbsoluteLayout.. I need to Fix the postion of the ActivityIndicator in centre of screen. I tried following code.

<ScrollView>
    <AbsoluteLayout VerticalOptions="FillAndExpand"
                    HorizontalOptions="FillAndExpand">
        <StackLayout BackgroundColor="White"
                     Padding="50,20,50,20"
                     Spacing="5"
                     AbsoluteLayout.LayoutBounds="0,0,1,1"
                     AbsoluteLayout.LayoutFlags="All"> 
            // have set of elements..
        </StackLayout>
        <ActivityIndicator IsVisible="{Binding IsBusy}"
                           IsRunning="{Binding IsBusy}"
                           Color="Black"
                           AbsoluteLayout.LayoutBounds="0.5,0.5,0.1,0.1"
                           AbsoluteLayout.LayoutFlags="All"/>
    </AbsoluteLayout>
</ScrollView>

and I find the result as its in the centre of the ScrollView.

I tried by placing the ActivityIndicatorout side the ScrollViewit simply gives white screen as output.

How do I fix the position of the ActivityIndicator in centre of screen ?


回答1:


As @Vahid said, if you want the ActivityIndicator over the ScrollView, you need to put both inside an AbsoluteLayout, like this:

<AbsoluteLayout VerticalOptions="FillAndExpand"
                HorizontalOptions="FillAndExpand">
    <ScrollView AbsoluteLayout.LayoutBounds="0,0,1,1"
                AbsoluteLayout.LayoutFlags="All"
                VerticalOptions="FillAndExpand"
                HorizontalOptions="FillAndExpand">
        <StackLayout BackgroundColor="White"
                     Padding="50,20,50,20"
                     Spacing="5">
            // Your stuff goes here
        </StackLayout>
    </ScrollView>
    <AbsoluteLayout BackgroundColor="#22000000"
                    AbsoluteLayout.LayoutBounds="0.5,0.5,1,1"
                    AbsoluteLayout.LayoutFlags="All"
                    IsVisible="{Binding IsBusy}">
        <ActivityIndicator Color="Black"
                           AbsoluteLayout.LayoutBounds="0.5,0.5,0.1,0.1"
                           AbsoluteLayout.LayoutFlags="All"
                           IsVisible="True"
                           IsRunning="True"/>
    </AbsoluteLayout>
</AbsoluteLayout>

Notice that I added an extra AbsoluteLayout that works like a 'wait overlay' over the ScrollView only - not the whole screen.




回答2:


Create a grid page with one row and one column. Define both your ActivityIndicatorLayout and ScrollLayout to be in row 0 and column 0. I add the Content before the Activity Indicator.




回答3:


You can use Rg.Plugins.Popup
Design popup page with activity indicator and you can display it wherever you want.



来源:https://stackoverflow.com/questions/48295792/xamarin-forms-how-to-fix-activity-indicator-in-centre-of-screen-in-scrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!