2014-07-18 40 views
1

我在Xamarin.Android上有应用程序,我在其中使用了PullToRefresharp。它适用于PC上的模拟器,但它不适用于任何设备。当我试图用此组件启动布局时 - 布局根本不加载。PullToRefresharp在设备上不起作用

<pulltorefresharp.android.views.ViewWrapper 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
      <pulltorefresharp.android.widget.ScrollView 
       android:id="@+id/textAreaScroller" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_x="0px" 
       android:layout_y="25px" 
       android:scrollbars="vertical"> 
       <LinearLayout 
        android:minWidth="25px" 
        android:minHeight="25px" 
        android:orientation="vertical" 
        android:background="#E6E7E8" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:id="@+id/linearLayout1"> 
        <TableLayout 
         android:minWidth="25px" 
         android:minHeight="25px" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:id="@+id/archive_table" /> 
       </LinearLayout> 
      </pulltorefresharp.android.widget.ScrollView> 
     </pulltorefresharp.android.views.ViewWrapper> 

后面的代码:

scrollView = FindViewById<PullToRefresharp.Android.Widget.ScrollView>(Resource.Id.textAreaScroller); 
       if (scrollView != null) { 
        scrollView.RefreshActivated += HandleRefreshActivated; 
       } 

private void HandleRefreshActivated (object sender, EventArgs e) 
     {   
      scrollView.OnRefreshCompleted(); 
     } 

可能是我设置didin't任何财产。我希望有人能帮助我。

回答

2

我建议你在这里使用了Android V4控制一个很简单的例子来使用它

首先添加了Android支持V4组件

XML实现

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:minWidth="25px" 
    android:minHeight="25px"> 
    <android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/swipe1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <ListView 
      android:minWidth="25px" 
      android:minHeight="25px" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/listView1" /> 
    </android.support.v4.widget.SwipeRefreshLayout> 
</LinearLayout> 

代码实现

ListView listView = null; 
     SwipeRefreshLayout swipe = null; 

     protected override void OnCreate (Bundle bundle) 
     { 
      base.OnCreate (bundle); 

      // Set our view from the "main" layout resource 
      SetContentView (Resource.Layout.Main); 

      listView = FindViewById<ListView> (Resource.Id.listView1); 
      swipe = FindViewById<SwipeRefreshLayout> (Resource.Id.swipe1); 

      swipe.Refresh += (sender, e) => { 
       swipe1.Refreshing = false; 
       ReloadDataMethod(); 
      }; 

      swipe.SetColorScheme (Android.Resource.Color.HoloBlueBright, 
       Android.Resource.Color.HoloGreenLight, 
       Android.Resource.Color.HoloOrangeLight, 
       Android.Resource.Color.HoloRedLight); 
     } 

它的一个非常简单的实现方法 希望它可以帮助你,如果你有任何问题随时问我

+0

也许你可以解释为什么你的代码工作,他没有,或者他的代码丢失。 –

+2

我更喜欢使用原生的Android控件,我从来没有使用他使用的控件,但本地控件完美地适用于我 –

+0

我试图按照上面的建议使用SwipeRefreshLayout,但我有错误:[mono-rt] android。 view.InflateException:二进制XML文件行#1:错误膨胀类swipetorefresh.ScrollChildSwipeRefreshLayout –

相关问题