2016-04-15 17 views
0

私はFacebookのような操作をしたい、スクロールビューを負のyまでドラッグすると、アクティビティインジケータが表示され、ビューが更新されます。スクロールでScrollViewをリフレッシュする

次のコードを実装すると、IOS上で動作しています。しかし、Androidデバイスで実行すると、スクロールyは0以上の値しか持たないように見え、スクロールしてスクロールすることはできません。

async void ContentScrollView_Scrolled(object sender, ScrolledEventArgs e) 
{ 
    if (!hold) 
    { 
     if (ContentScrollView.ScrollY < -70) 
     { 
      hold = true; 
      scrollLoadingBar.IsRunning = true; 
      scrollLoadingBar.IsVisible = true; 

      netStructure structure = await Net.getWebServicesData("chart.asmx/GetCampaignChart?username=" + App.username + "&password=" + App.password + "&campid=" + App.campid + "&noOfChart=1&callback="); 
      if (structure.status) 
      { 
       App.chart1 = structure.returnObject; 
       setcampaignchart(); 
      } 
      else 
      { 
       await DisplayAlert("Loading Chart Error", structure.errorMessage, "Ok"); 
      } 

      scrollLoadingBar.IsVisible = false; 
      scrollLoadingBar.IsRunning = false; 
     } 
    } 
    if (hold) 
    { 
     if (ContentScrollView.ScrollY == 0) 
     { 
      hold = false; 
     } 
    } 
} 

Androidでこの機能を使用するにはどうすればよいですか?

答えて

1

私はXamarin.Formsタグのため、あなたの質問では言及していないにもかかわらず、Xamarin.Formsソリューションがほしいと思っています。それを手作業でコード化する必要はありません。ジェームス・モンテマニョーニョは私たちのために全力を尽くしました。ここにPullToRefreshLayout githubのページへのリンクです。 XamlのScrollViewの場所にPullToRefreshLayoutを追加し、そのコンテンツとしてScrollViewを設定するだけです。

編集:@cheesebaronの提案通りに説明しています。

プラグインNugetパッケージRefractored.XamForms.PullToRefreshをインストールできます。

次に、PullToRefreshLayoutをScrollViewの親として追加することで、PullToRefreshアクションを実装できます。 Githubの例を引用しています。

<?xml version="1.0" encoding="UTF-8"?> 
<ContentPage 
xmlns="http://xamarin.com/schemas/2014/forms" 
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
x:Class="RefreshSample.Views.ScrollViewXamlPage" 
xmlns:controls="clr-namespace:Refractored.XamForms.PullToRefresh;assembly=Refractored.XamForms.PullToRefresh" 
Title="Xaml Scroll"> 
<controls:PullToRefreshLayout 
     IsPullToRefreshEnabled="True" 
     RefreshCommand="{Binding RefreshCommand}" 
     IsRefreshing="{Binding IsBusy}" 
     RefreshColor="Blue"> 
     <ScrollView 
     HorizontalOptions="FillAndExpand" 
     VerticalOptions="FillAndExpand"> 
     <StackLayout 
       HorizontalOptions="FillAndExpand" 
       VerticalOptions="FillAndExpand"> 
      <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Blue"/> 
      <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Red"/> 
      <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Yellow"/> 
      <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Purple"/> 
      <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Maroon"/> 
      <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Blue"/> 
      <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Red"/> 
      <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Yellow"/> 
      <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Purple"/> 
      <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Maroon"/> 
     </StackLayout> 
     </ScrollView> 
    </controls:PullToRefreshLayout> 
</ContentPage> 
+0

このライブラリの使用方法について詳しく説明してください。答えは、それは非常に低品質であり、実際にStackOverflowの品質に適合していないので – Cheesebaron

+0

私はどのように彼の仕事をプロジェクトに実装するか尋ねるかもしれません? –

+0

@RyanShine [パッケージ]フォルダを右クリックし、[パッケージの追加]をクリックします。 [パッケージの追加]ウィンドウがポップアップ表示されます。 Refractored.XamForms.PullToRefreshを検索します。図書館は左側にあります。それを選択し、[パッケージの追加]をクリックします。今度はライブラリがプロジェクトに追加され、Xamlコードのウィジェットを参照すると、 – Sreeraj

関連する問題