[英]Recyclerview fully scroll to position
我的recyclerview应该打开第一个关闭的项目。 为此,我写了以下几行。
LinearLayoutManager llm = new LinearLayoutManager(getActivity());
llm.scrollToPosition(1);
paletteRecyclerView.setLayoutManager(llm);
我想检查是否可以完全滚动到位置1。 如果我的recyclerview很小,则必须在不关闭第一项的情况下将其打开。 我该如何检查?
尝试以下代码...
LinearLayoutManager llm = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(llm);
RecyclerView.Adapter adapter = new YourAdapter();
recyclerView.setAdapter(adapter);
recyclerView.scrollToPosition(position);
我假设您想知道RecyclerView中是否有要滚动的项目。 因此,将适配器设置为recyclerView之后,您可以进行以下检查。
recyclerView.post(new Runnable() {
@Override
public void run() {
int recyclerViewheight = recyclerView.getHeight();
int totalChildViewsHeight = recyclerView.computeVerticalScrollRange();
if (recyclerViewheight > totalChildViewsHeight) {
//there is no scroll (there are no more items to scroll)
} else {
//there is scroll (there are items to scroll)
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.