您的位置:首页 > 其它

PullToRefreshListView 变成RecyclerView

2016-04-19 12:31 316 查看
继承PullToRefreshBase 复写滑动判断

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;

import com.handmark.pulltorefresh.library.PullToRefreshBase;

/**
* @author xuanyouwu
* @email xuanyouwu@163.com
* @time 2016-04-19 11:02
* <p/>
* 下拉刷新 上拉加载 自动刷新PullRecyclerView
*/
public class PullRecyclerView extends PullToRefreshBase<RecyclerView> {

public PullRecyclerView(Context context, Mode mode, AnimationStyle animStyle) {
super(context, mode, animStyle);
}

public PullRecyclerView(Context context, Mode mode) {
super(context, mode);
}

public PullRecyclerView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public PullRecyclerView(Context context) {
super(context);
}

@Override
public Orientation getPullToRefreshScrollDirection() {
return Orientation.VERTICAL;
}

@Override
protected RecyclerView createRefreshableView(Context context, AttributeSet attrs) {
RecyclerView recyclerView = new RecyclerView(context, attrs);
return recyclerView;
}

@Override
protected boolean isReadyForPullEnd() {
return DesignViewUtils.isSlideToBottom(getRefreshableView());
}

@Override
protected boolean isReadyForPullStart() {
return DesignViewUtils.isSlideToTop(getRefreshableView());
}

}
<pre name="code" class="java">import android.support.design.widget.AppBarLayout;import android.support.v7.widget.RecyclerView;/*** @author xuanyouwu* @email xuanyouwu@163.com* @time 2016-04-13 16:25*/public class DesignViewUtils {/*** AppBarLayout 完全显示 打开状态** @param verticalOffset* @return*/public static boolean isAppBarLayoutOpen(int verticalOffset) {return verticalOffset >= 0;}/*** AppBarLayout 关闭或折叠状态** @param appBarLayout* @param verticalOffset* @return*/public static boolean isAppBarLayoutClose(AppBarLayout appBarLayout, int verticalOffset) {if (appBarLayout == null) return false;return appBarLayout.getTotalScrollRange() == Math.abs(verticalOffset);}/*** RecyclerView 滚动到底部 最后一条完全显示** @param recyclerView* @return*/public static boolean isSlideToBottom(RecyclerView recyclerView) {if (recyclerView == null) return false;if (recyclerView.computeVerticalScrollExtent() + recyclerView.computeVerticalScrollOffset() >= recyclerView.computeVerticalScrollRange())return true;return false;}/*** RecyclerView 滚动到顶端** @param recyclerView* @return*/public static boolean isSlideToTop(RecyclerView recyclerView) {if (recyclerView == null) return false;return recyclerView.computeVerticalScrollOffset() <= 0;}}

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: