在SwipeRefreshLayout中禁用刷新,同时允许拖动事件从上到下发生在回收视图,可以通过以下步骤实现:
public class CustomSwipeRefreshLayout extends SwipeRefreshLayout {
private View mTarget;
public CustomSwipeRefreshLayout(Context context) {
super(context);
}
public CustomSwipeRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean canChildScrollUp() {
if (mTarget != null) {
if (mTarget instanceof RecyclerView) {
RecyclerView recyclerView = (RecyclerView) mTarget;
return recyclerView.canScrollVertically(-1);
} else {
return mTarget.canScrollVertically(-1);
}
}
return super.canChildScrollUp();
}
@Override
public void setRefreshing(boolean refreshing) {
super.setRefreshing(refreshing);
if (!refreshing) {
setEnabled(true);
}
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
final View target = mTarget;
final float y = ev.getY();
if (target != null && y < target.getTop()) {
setEnabled(false);
}
}
return super.onInterceptTouchEvent(ev);
}
@Override
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
if (mTarget != null && mTarget instanceof RecyclerView) {
RecyclerView recyclerView = (RecyclerView) mTarget;
recyclerView.requestDisallowInterceptTouchEvent(disallowIntercept);
}
super.requestDisallowInterceptTouchEvent(disallowIntercept);
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
if (!enabled) {
setRefreshing(false);
}
}
@Override
public void setOnChildScrollUpCallback(OnChildScrollUpCallback callback) {
super.setOnChildScrollUpCallback(callback);
if (callback != null) {
mTarget = callback.getScrollUpView();
}
}
}
<com.example.CustomSwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Your content here -->
</com.example.CustomSwipeRefreshLayout>
通过以上步骤,你可以在SwipeRefreshLayout中禁用刷新,同时允许拖动事件从上到下发生在回收视图。请注意,这里的CustomSwipeRefreshLayout类只是一个示例,你可以根据自己的需求进行修改和扩展。
腾讯云相关产品和产品介绍链接地址:
请注意,以上链接仅为示例,具体的产品选择和推荐应根据实际需求和情况进行决策。
领取专属 10元无门槛券
手把手带您无忧上云