C# 为什么在添加活动指示器后控件变得不居中
我一直在玩弄活动指示器,试图将它们添加到我的视图中,使其居中,使其覆盖在其他控件之上,等等 另一个线程()中接受的答案实际上向我展示了如何完成所有这些,因此我将其添加到测试项目中进行验证 我现在遇到的问题是,在我将控件添加到XAML之后,它现在将控件移动到屏幕的左上角,我想知道我现在需要做哪些更改才能使控件再次居中 以下是我的测试项目中的XAML:C# 为什么在添加活动指示器后控件变得不居中,c#,xamarin.forms,activity-indicator,C#,Xamarin.forms,Activity Indicator,我一直在玩弄活动指示器,试图将它们添加到我的视图中,使其居中,使其覆盖在其他控件之上,等等 另一个线程()中接受的答案实际上向我展示了如何完成所有这些,因此我将其添加到测试项目中进行验证 我现在遇到的问题是,在我将控件添加到XAML之后,它现在将控件移动到屏幕的左上角,我想知道我现在需要做哪些更改才能使控件再次居中 以下是我的测试项目中的XAML: <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xml
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="ActivityIndicator.MainPage">
<AbsoluteLayout HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<StackLayout HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand">
<!-- Place new controls here -->
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand" />
<Button Text="Button1"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"/>
</StackLayout>
<AbsoluteLayout BackgroundColor="#22000000"
AbsoluteLayout.LayoutBounds="0.5,0.5,1,1"
AbsoluteLayout.LayoutFlags="All"
IsVisible="True">
<ActivityIndicator Color="Black"
AbsoluteLayout.LayoutBounds="0.5,0.5,0.1,0.1"
AbsoluteLayout.LayoutFlags="All"
IsVisible="True"
IsRunning="True"/>
</AbsoluteLayout>
</AbsoluteLayout>
根据您的描述,您只需要将ActivityIndicator放在屏幕中央,我做了一个示例,您可以看一下:
<RelativeLayout HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand">
<Grid
x:Name="SegmentGrid"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Text="Welcome to Xamarin.Forms!" />
<Button Grid.Row="1" Text="Button1" />
<ActivityIndicator
Grid.RowSpan="2"
HorizontalOptions="CenterAndExpand"
IsRunning="True"
VerticalOptions="CenterAndExpand"
Color="Black" />
</Grid>
</RelativeLayout>
我遇到了同样的问题,解决方法如下。我在viewmodelbase中创建了一个方法,用于封装操作的执行
`protected async Task ExecuteAndWait(Action action)
{
var popup = new PopupWaiting();
IPopupNavigation ipn = PopupNavigation.Instance;
await ipn.PushAsync(popup);
action.Invoke();
await ipn.RemovePageAsync(popup);
}`
我正在使用Rg.Plugins.Popup.Contracts插件来管理加载层。
此模型的优点是不必更改xaml。您应该正确定位绝对布局边界。你试过这个吗?你会很容易用它吗?谢谢你,巴拉斯。有没有办法用IsBusy将其绑定到活动指示器?该示例显示了所有直接绑定到按钮的代码,然后在设置的时间限制内显示,因此我不知道如何将其转换为使用我的应用程序,我想我已经找到了答案。我试试看。谢谢Bharath@user1818298,任何更新,如果我的回复对您有帮助,请记住将我的回复标记为“回复”,谢谢。