简体   繁体   English

ItemTouchHelper和SwipeRefreshLayout(RecyclerView)

[英]ItemTouchHelper and SwipeRefreshLayout (RecyclerView)

I want to use the new ItemTouchHelper from the v7 design library. 我想使用v7设计库中的新ItemTouchHelper。 I use it inside of a SwipeRefreshLayout. 我在SwipeRefreshLayout中使用它。

The problem is that with the SwipeRefreshLayout the animation for the swipe to dismiss is wrong and buggy. 问题是,使用SwipeRefreshLayout,滑动解除的动画是错误的和错误的。

Anyone knows how to fix this? 谁知道如何解决这个问题?

You could disable your SwipeRefreshLayout as long as you are swiping. 只要您正在滑动,就可以禁用SwipeRefreshLayout。

final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() {
    @Override
    public int getMovementFlags(RecyclerView recyclerView, ViewHolder viewHolder) {
        return makeMovementFlags(0, ItemTouchHelper.START | ItemTouchHelper.END);
    }

    @Override
    public boolean onMove(RecyclerView recyclerView, ViewHolder viewHolder, ViewHolder target) {
        return false;
    }

    @Override
    public void onSwiped(ViewHolder viewHolder, int direction) {
        // do something
    }

    @Override
    public void onSelectedChanged(ViewHolder viewHolder, int actionState) {
        super.onSelectedChanged(viewHolder, actionState);
        final boolean swiping = actionState == ItemTouchHelper.ACTION_STATE_SWIPE;
        swipeRefreshLayout.setEnabled(!swiping);
    }
});
itemTouchHelper.attachToRecyclerView(recyclerView);

one of many: 其中之一:

 /**
 * Notify the widget that refresh state has changed. 
 * method to avoid bug in setRefreshing(boolean)     
 * Do not call this when refresh is triggered by a swipe gesture.
 * @param swipeRefreshLayout - layout, take care not to pass null parameter
 * @param isRefreshing - whether or not the view should show refresh progress.
 *               
 */
public static void setRefreshing(final SwipeRefreshLayout swipeRefreshLayout, final boolean isRefreshing) {
    swipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            swipeRefreshLayout.setRefreshing(isRefreshing);
        }
    });
}

some other possibilities: 其他一些可能性:

posted bug with some workarounds 发布了一些变通方法的bug

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM