0

我的 recyclerview 应该打开第一个关闭的项目。为此,我写了这些行。

 LinearLayoutManager llm = new LinearLayoutManager(getActivity());
 llm.scrollToPosition(1);
 paletteRecyclerView.setLayoutManager(llm);

我想检查是否可以完全滚动到位置 1。如果我的 recyclerview 很小,我必须在不关闭第一个项目的情况下打开它。我怎样才能检查它?

4

2 回答 2

0

试试下面的代码...

LinearLayoutManager llm = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(llm);

RecyclerView.Adapter adapter = new YourAdapter();
recyclerView.setAdapter(adapter);

recyclerView.scrollToPosition(position);
于 2016-12-07T09:04:30.947 回答
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)
            }
        }
    });
于 2016-12-07T09:15:25.313 回答