这是我的XAML
代码我试图将ActivityIndicator
放在其他视图之上,但它根本没有显示为什么?
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" BackgroundImage="background_nonedit.png" Title="Citizen Reporter" x:Class="BBSTV.CitizenReporter">
<ScrollView>
<RelativeLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<StackLayout VerticalOptions="Center" HorizontalOptions="Fill" Padding="10" RelativeLayout.XConstraint="{ConstraintExpression Type=Constant, Constant=0}" RelativeLayout.YConstraint="{ConstraintExpression Type=Constant, Constant=0}">
<Grid x:Name="SegmentGrid" RowSpacing="10" ColumnSpacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
</Grid>
<Image x:Name="citizenImage" WidthRequest="400" HeightRequest="220" />
<Label VerticalOptions="Center" HorizontalOptions="Center" Margin="8" x:Name="attachment_label" />
<Entry Placeholder="News Title" Margin="8" VerticalOptions="Center" HeightRequest="40" />
<Entry Placeholder="News Details" Margin="8" VerticalOptions="Center" HeightRequest="90" />
<Button Text="CHOOSE PHOTO" Margin="8" Clicked="onChoosePhoto" TextColor="White" BackgroundColor="#4D7EE1" />
<Button Text="TAKE PHOTO" Margin="8" Clicked="onTakePhoto" TextColor="White" BackgroundColor="#4D7EE1" />
<Button Text="CHOOSE VIDEO" Margin="8" Clicked="onChooseVideo" TextColor="White" BackgroundColor="#4D7EE1" />
<Button Text="TAKE VIDEO" Margin="8" Clicked="onTakeVideo" TextColor="White" BackgroundColor="#4D7EE1" />
<Button Text="UPLOAD REPORT" Margin="9" Clicked="UploadFile_Clicked" TextColor="White" BackgroundColor="#F399FC " />
</StackLayout>
<ActivityIndicator x:Name="activity_i_citizenReport" Color="Black"
VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"
/>
</RelativeLayout>
</ScrollView>
</ContentPage>
答案 0 :(得分:1)
相对布局会将控件放在与其兄弟姐妹相关的位置,因此它可能会将堆栈布局渲染到指标的顶部,或者只是在其下方并且看不见。记录在案here。
我只是将它放在滚动视图的外部,因为滚动视图的内容大小可变,因此有时可能有点难以计算死点,而如果您直接将活动控件分配给内容页面它总是在中心。如果以下方法不起作用,您可能必须使用Z-Index。
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" BackgroundImage="background_nonedit.png" Title="Citizen Reporter" x:Class="BBSTV.CitizenReporter">
<ContentPage.Content>
<ActivityIndicator x:Name="activity_i_citizenReport" Color="Black"
VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"/>
<ScrollView>
<RelativeLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<StackLayout VerticalOptions="Center" HorizontalOptions="Fill" Padding="10" RelativeLayout.XConstraint="{ConstraintExpression Type=Constant, Constant=0}" RelativeLayout.YConstraint="{ConstraintExpression Type=Constant, Constant=0}">
<Grid x:Name="SegmentGrid" RowSpacing="10" ColumnSpacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
</Grid>
<Image x:Name="citizenImage" WidthRequest="400" HeightRequest="220" />
<Label VerticalOptions="Center" HorizontalOptions="Center" Margin="8" x:Name="attachment_label" />
<Entry Placeholder="News Title" Margin="8" VerticalOptions="Center" HeightRequest="40" />
<Entry Placeholder="News Details" Margin="8" VerticalOptions="Center" HeightRequest="90" />
<Button Text="CHOOSE PHOTO" Margin="8" Clicked="onChoosePhoto" TextColor="White" BackgroundColor="#4D7EE1" />
<Button Text="TAKE PHOTO" Margin="8" Clicked="onTakePhoto" TextColor="White" BackgroundColor="#4D7EE1" />
<Button Text="CHOOSE VIDEO" Margin="8" Clicked="onChooseVideo" TextColor="White" BackgroundColor="#4D7EE1" />
<Button Text="TAKE VIDEO" Margin="8" Clicked="onTakeVideo" TextColor="White" BackgroundColor="#4D7EE1" />
<Button Text="UPLOAD REPORT" Margin="9" Clicked="UploadFile_Clicked" TextColor="White" BackgroundColor="#F399FC " />
</StackLayout>
</RelativeLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>
答案 1 :(得分:1)
答案 2 :(得分:1)
我在项目中所做的工作
在Grid
我使用ScrollView
作为<Grid HorizontalOptions="FillAndExpand">
<ScrollView HorizontalOptions="FillAndExpand">
<!----Views----->
</ScrollView>
<Frame Padding="50,30,50,30" HasShadow="true" BackgroundColor="#80000000" Grid.Row="0" Grid.Column="0" IsVisible="{Binding IsLoading}" VerticalOptions="Center" HorizontalOptions="Center">
<ActivityIndicator Color="White" VerticalOptions="Center" HorizontalOptions="Center" x:Name="actInd" IsRunning="{Binding IsLoading}" IsVisible="{Binding IsLoading}" />
</Frame>
</Grid>
的父级。
INotifyPropertyChanged
在Page
中实施BindingContext = this;
。
在构造函数中,设置
PropertyChangedEventHandler
之后,使用我们的自定义属性在您的页面中创建private bool isLoading;
public bool IsLoading
{
get
{
return isLoading;
}
set
{
isLoading = value;
RaisePropertyChanged("IsLoading");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
。
IsLoading
现在我们只需更改private void doStuffs()
{
IsLoading = true;
IsBusy = true;
//Do any stuffs
IsLoading = false;
IsBusy = false;
}
的值即可显示ActivityIndicator。
byte[]
答案 3 :(得分:0)
就我所关注的问题而言,所有关于将其置于StackLayout
中的讨论都是h ..我的定义是Grid
,但根本不显示。当我在Windows 10(UWP)上运行它时,如果仅IsRunning
设置为true
,则根本不会显示;但如果您将IsEnabled
或IsVisible
设置为true
与IsRunning
结合,则会显示约两秒钟,然后淡出并且永不显示再次。请注意,IsRunning
,IsEnabled
和IsVisible
仅设置一次并且没有时间密集型操作正在运行UI线程。
这绝对是个错误。我会使用动画GIF,直到Xamarin团队得到修复。如果它无法在所有平台上运行,那么它基本上是无用的。