PullToRefresharp在设备上不起作用

时间:2014-07-18 15:38:48

标签: android xamarin pull-to-refresh

我在Xamarin.Android上有app,我在其中使用了PullToRefresharp。它适用于Pc上的仿真器,但它不适用于任何设备。当我尝试使用此组件启动布局时 - 布局根本不会加载。

<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 ();
        }

可能是我没有设置任何财产。我希望有人可以帮助我。

1 个答案:

答案 0 :(得分:3)

我建议你在这里使用Android V4控件一个非常简单的例子来使用它

首先添加Android Support 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);
        }

这是一个非常简单的实现, 希望对您有所帮助,如果您有任何问题请随时问我