2016-05-02 17 views
0

私はXamarinフォームを使用していて、画面のオーバーレイローダーを作成しようとしています。私の発見から、私は絶対レイアウトを使用する必要があります。私はいくつかの画面で動作するようにローダーを実現しましたが、画面が少し複雑(入れ子になったスクロールビュー、グリッドなどを使用)しても動作しないようです。以下は、仕事んので、コードのサンプルです:xamarinフォームを使用してモバイルアプリケーションにオーバレイローダーを作成します。

次のコードは、 が何をするかである
<AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"> 
    <StackLayout Padding="10" Orientation="Vertical" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1"> 
     <StackLayout Padding="0,85,0,0"> 
     <Image Source="myimage.png" HorizontalOptions="Center" VerticalOptions="Start" /> 
     </StackLayout> 

     <StackLayout Orientation="Vertical" Padding="10, 5, 10, 5" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"> 
     <Label Text="This works perfect"></Label> 
     </StackLayout> 
    </StackLayout> 

    <!-- Loader --> 
    <ContentView BackgroundColor="#222222" 
       Opacity="0.3" 
       AbsoluteLayout.LayoutFlags="All" 
       AbsoluteLayout.LayoutBounds="0,0,1,1" 
       IsVisible="{Binding IsIndicatorActive}"> 
     <ActivityIndicator AbsoluteLayout.LayoutFlags="All" 
         AbsoluteLayout.LayoutBounds="0,0,1,1" 
         VerticalOptions="{StaticResource LoaderPosition}" 
         HorizontalOptions="{StaticResource LoaderPosition}" 
         IsEnabled="{Binding IsIndicatorActive}" 
         IsRunning="{Binding IsIndicatorActive}" 
         IsVisible="{Binding IsIndicatorActive}" /> 
    </ContentView> 
    </AbsoluteLayout> 

は、NOT作品:それは事実とは何かを持っている私の理解から

<AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"> 
    <StackLayout Orientation="Vertical" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1"> 
     <ScrollView> 
     <StackLayout Padding="0,85,0,0"> 
      <Image Source="myimage.png" HorizontalOptions="Center" VerticalOptions="Start" /> 
     </StackLayout> 

     <StackLayout Orientation="Vertical" Padding="10, 5, 10, 5" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"> 
      <Label Text="This doesn't work"></Label> 
     </StackLayout> 
     </ScrollView> 

     <Grid HorizontalOptions="FillAndExpand" VerticalOptions="EndAndExpand" ColumnSpacing="0" RowSpacing="0"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
     </Grid.RowDefinitions> 

     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="2*" /> 
      <ColumnDefinition Width="2*" /> 
     </Grid.ColumnDefinitions> 

     <Button Grid.Row="0" Grid.Column="0" HorizontalOptions="FillAndExpand" Text="Button1" Command="{Binding Button2Command}" /> 
     <Button Grid.Row="0" Grid.Column="1" HorizontalOptions="FillAndExpand" Text="Button2" Command="{Binding Button2Command}" /> 
     </Grid> 
    </StackLayout> 

    <!-- Loader --> 
    <ContentView BackgroundColor="#222222" 
       Opacity="0.3" 
       AbsoluteLayout.LayoutFlags="All" 
       AbsoluteLayout.LayoutBounds="0,0,1,1" 
       IsVisible="{Binding IsIndicatorActive}"> 
     <ActivityIndicator AbsoluteLayout.LayoutFlags="All" 
         AbsoluteLayout.LayoutBounds="0,0,1,1" 
         VerticalOptions="{StaticResource LoaderPosition}" 
         HorizontalOptions="{StaticResource LoaderPosition}" 
         IsEnabled="{Binding IsIndicatorActive}" 
         IsRunning="{Binding IsIndicatorActive}" 
         IsVisible="{Binding IsIndicatorActive}" /> 
    </ContentView> 
    </AbsoluteLayout> 

スクロールビューとグリッドビューはです。管理されたレイアウトと絶対レイアウトはです。アンマネージドレイアウトだから、完全な絶対レイアウトを占有したstacklayoutを置くと、 rollviewとgridviewは、親(HTMLがこれを処理する方法)からの相対的なstacklayoutを示します。明らかに、これはそのような方法で処理されません(代わりに私はただの空白の画面が表示されます)。

どのように私はこの問題を回避することができ、自分の画面表示に影響を与えずにローダーを表示させることができますか?ありがとう!

答えて

0

多分これが容易になります。

iOSの実装:

http://pastie.org/10821570

https://components.xamarin.com/view/andhud

https://components.xamarin.com/view/btprogresshud

はあなたが唯一の依存関係サービスを使用する必要があり、それらを実装するには

Androidの実装:

http://pastie.org/10821571

インタフェースの実装:

using System; 
namespace YourNameSpace 
{ 
    public interface IHudService 
    { 
     void ShowHud(string ProgressText = "Loading..."); 
     void HideHud(); 
     void SetText(string Text); 
     void SetProgress(double Progress, string ProgressText = ""); 
    } 
} 

そして単に使用し、それを使用する:

DependencyService.Get<IHudService>().ShowHud(); 
//Your Task... 
DependencyService.Get<IHudService>().HideHud(); 
関連する問題