我知道很多次问过类似的问题,但它无法解决我的问题。所以我在这里问。我有一个带有swiperefresh布局的recyclerView。我使用过这段代码
recyclerView1.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
//super.onScrollStateChanged(recyclerView, newState);
try {
int firstPos = mLinearLayoutManager.findFirstCompletelyVisibleItemPosition();
if (refreshLayout != null) {
if (firstPos > 0) {
refreshLayout.setEnabled(false);
} else {
activity.refreshLayout.setEnabled(true);
if (recyclerView1.getScrollState() == 1)
if (activity.refreshLayout.isRefreshing())
recyclerView1.stopScroll();
}
}
} catch (Exception e) {
}
}
});
区分recyclelerView和刷卡刷新布局的滚动。但是我使用这个[Is there an addHeaderView equivalent for RecyclerView?为这个recyclerView添加了一个标题。现在,recyclerview中的标题高度太大,因此在小型设备中
int firstPos = mLinearLayoutManager.findFirstCompletelyVisibleItemPosition();
当只有一半标题可见时,返回0。它正在启用swiperefreshlayout。所以我无法在recyclerView中看到整个标题。任何人都可以帮我解决这个问题。
由于
答案 0 :(得分:0)
LinearLayoutManager llm = new LinearLayoutManager(getActivity());
refreshLayout.setOnRefreshListener(new PullRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
refreshLayout.setRefreshing(true);
// start refresh
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
refreshLayout.setRefreshing(false);
}
}, 5000);
}
});
recList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
refreshLayout.setEnabled(llm.findFirstCompletelyVisibleItemPosition() == 0);
}
});