我正在尝试从Firebase检索数据,然后将其显示在回收站视图中。我将布局设置为reverselayout = true。但是,当我运行活动时,视图从底部开始。如下面所注释的,我尝试使用scrollToPosition运行应用程序时更改了初始位置,但是仍然没有任何变化。有人有与此问题相关的解决方案吗?
我已经尝试过:https://stackoverflow.com/a/26876044/7825519 但还是要从头开始。
mRecyclerView!!.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false)
(mRecyclerView!!.layoutManager as LinearLayoutManager).reverseLayout = true
(mRecyclerView!!.layoutManager as LinearLayoutManager).stackFromEnd = true
mRecyclerView?.scrollToPosition(3)
// mRecyclerView?.smoothScrollToPosition(3)
// (mRecyclerView!!.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(3,0)
// mNestedScrollView?.scrollTo(0,3)
mAdapter = DiscoverAdapter(mItems, mPostKey, Static.mLikedPosts, this)
mRecyclerView!!.adapter = mAdapter
val spacingInPixels = resources.getDimensionPixelSize(R.dimen.margin_between_card)
mRecyclerView!!.addItemDecoration(SpacesItemDecoration(spacingInPixels))
答案 0 :(得分:0)
首先,删除使recyclerview从底部开始的两行。 设置适配器后设置滚动:
mRecyclerView!!.adapter = mAdapter
mRecyclerView?.scrollToPosition(3)
答案 1 :(得分:0)
尝试使用scrollToPosition
的{{1}}方法设置post