5

我在我的项目中使用 Staggeredgridview。

我已经从这里下载了 StaggeredGridView 库和演示:https ://github.com/maurycyw/StaggeredGridViewDemo https://github.com/maurycyw/StaggeredGridView

我需要为整个网格视图 PullToRefresh

谢谢大家

4

2 回答 2

3

StaggeredGridView刚刚在 Chris Banes Android-PullToRefresh中添加了支持。还支持Actionbar-PullToRefresh for ActionBarSherlock.

于 2013-11-01T08:18:27.843 回答
0

在 SwipeRefreshLyout 中包含 gridview。

     <android.support.v4.widget.SwipeRefreshLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/swipeLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

     </android.support.v4.widget.SwipeRefreshLayout>

在 onViewCreated 中为 gridview 添加 onScroll 监听器。设置刷新启用时的条件。

    swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swipeLayout);
    swipeRefreshLayout.setColorSchemeResources(R.color.theme_color);
    swipeRefreshLayout.setOnRefreshListener(this);
    gridView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {
        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            int dist = gridView.getDistanceToTop();

            if (dist == 0)
                swipeRefreshLayout.setEnabled(true);
            else {
                swipeRefreshLayout.setEnabled(false);
            }

        }
    });

然后添加一个 onRefresh 函数。

     @Override
    public void onRefresh() {
      if (!swipeRefreshLayout.isRefreshing()) {
          swipeRefreshLayout.setRefreshing(true);
      }
      //add functionality then set refresh to false
      swipeRefreshLayout.setRefreshing(false);
    }
于 2015-08-19T14:19:31.373 回答