我有一个 Activity 和 10 个根据 Activity 绘制的 fragment 。 Activity 上的所有 fragment 都需要“拖动刷新”。我添加了“滑动刷新布局”来创建它。现在,当我点击开关时,一切都很好;但是当我尝试将其从一个阶段拖动到另一个阶段时,会出现滑动刷新,并且开关只是停留在相同的位置。那么如何才能在用户将开关从一个位置拖动到另一个位置时及时阻止滑动刷新布局的刷新呢?
我试着把它做成这样:
onOffSwitchSettings.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
((MainActivity) getActivity()).swipeContainer.setRefreshing(false);
return false;
}
});
但是之后我怎样才能打开它呢?
最佳答案
根据SwipeRefreshLayout
引用:
The
SwipeRefreshLayout
will notify the listener each and every time the gesture is completed again; the listener is responsible for correctly determining when to actually initiate a refresh of its content. If the listener determines there should not be a refresh, it must callsetRefreshing(false)
to cancel any visual indication of a refresh. If an activity wishes to show just the progress animation, it should callsetRefreshing(true)
. To disable the gesture and progress animation, callsetEnabled(false)
on the view.
您忘记使用 ((MainActivity)getActivity()).swipeContainer.setEnabled(false)
方法。
另一个问题是,使用上面的方法您将永久禁用SRL
,因此您需要在操作正确时再次启用它,我的意思是不再有拖动。
希望对你有帮助
关于java - SwipeRefreshLayout 阻止 android.widget.switch 拖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40156495/