Skip to content

A library for Android , swipe to refresh content or load more

License

Notifications You must be signed in to change notification settings

excitedhaha/RefreshLoadLayout

Repository files navigation

RefreshLoadLayout

A library for Android , swipe to refresh or load more
License Download

#使用说明

  • 添加 gralde 依赖
    compile 'com.github.refreshloadlayout:refreshloadlayout:0.0.4'
    如果收到支持库不统一的警告,可修改为 compile ('com.github.refreshloadlayout:refreshloadlayout:0.0.4'){exclude group: 'com.android.support'}

  • 在布局中使用

      <com.github.refreshloadlayout.RefreshLoadLayout
      android:id="@+id/refreshLayout"
      app:loadingEnabled="true"
      app:refreshingEnabled="true"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
      <ListView
          android:id="@+id/listView"
          android:background="#fff"
          android:layout_width="match_parent"
          android:layout_height="match_parent"/>
      </com.github.refreshloadlayout.RefreshLoadLayout>
    
  • 下拉刷新

      refreshLoadLayout.setOnRefreshListener(new RefreshLoadLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
              refreshLoadLayout.postDelayed(new Runnable() {
                  @Override
                  public void run() {
                      refreshLoadLayout.endRefreshing();
                  }
              }, 3000);
          }
      });
    
  • 上滑加载

    refreshLoadLayout.setLoadingHandler(new RefreshLoadLayout.LoadingHandler() {
          @Override
          public boolean canLoadMore() {
              return listView.getCount()<26;
          }
    
          @Override
          public void onLoading() {
              refreshLoadLayout.postDelayed(new Runnable() {
                  @Override
                  public void run() {
                      ArrayAdapter<String> arrayAdapter= (ArrayAdapter<String>) listView.getAdapter();
                      arrayAdapter.add("a new data");
                      arrayAdapter.add("a new data");
                      refreshLoadLayout.endLoading();
                  }
              }, 2000);
    
          }
      });
    

其中 canLoadMore() 方法返回当前是否可以进行加载,即是否还有更多内容。 可设置是否需要在加载结束后将内容视图下滑一定距离,默认开启: refreshLoadLayout.setScrollDownAfterLoading(false);

  • 启用/关闭功能 默认开启下拉刷新关闭上滑加载更多,可以在xml中指定或者在代码中修改。 refreshLoadLayout.setRefreshingEnabled(false); refreshLoadLayout.setLoadingEnabled(true);

  • UI定制 目前共有两种指示器显示效果,默认实现的是仿新浪微博的,还有一种是Material 效果。 首先可以通过 refreshLoadLayout.getRefreshIndicator();refreshLoadLayout.getLoadMoreIndicator(); 对当前的指示器进行调整。 也支持扩展 RefreshIndicator 和 LoadMoreIndicator 来打造自己的指示器。 比如设置 Material 效果的指示器: MaterialIndicator materialIndicator=new MaterialIndicator(this); materialIndicator.getProgressView().setColorSchemeColors(Color.RED,Color.YELLOW); refreshLoadLayout.setRefreshIndicator(materialIndicator);

有问题欢迎提issue,我会尽快处理。如果对你有帮助,还请右上角star :)

About

A library for Android , swipe to refresh content or load more

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published