我的recyclerview应该打开关闭的第一个项目。为此,我写了这些内容。
LinearLayoutManager llm = new LinearLayoutManager(getActivity());
llm.scrollToPosition(1);
paletteRecyclerView.setLayoutManager(llm);
我想检查是否可以完全滚动到位置1。如果我的recyclerview很小,我必须打开它而不关闭第一项。我怎么检查呢?
答案 0 :(得分:0)
尝试使用以下代码...
LinearLayoutManager llm = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(llm);
RecyclerView.Adapter adapter = new YourAdapter();
recyclerView.setAdapter(adapter);
recyclerView.scrollToPosition(position);
答案 1 :(得分:0)
我假设你想知道在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)
}
}
});