2017-06-13 62 views
0

我想讓recycleview項目滾動通過點擊一個button.and我使用 lineLayoutManger.scrollToPositionWithOffset(position,0); 位置頂部是我想滾動項目postion.but當我進入活動,並具有init適配器。但是當我點擊buttton讓第五項滾動到頂部。但它只是在屏幕的底部。如果我再次點擊該按鈕,則顯示正常情況下第五個項目在頂部。項目不是同一高度。 whate我應該怎麼do.I已搜索到很多article.but沒有answer.thanks錯誤的效果圖see this picture使用LinelayoutManager.scrollToPositionWithOffset時,如何讓項目滾動到Recycleview的頂部?第一次不影響

回答

0

從recyclerView名單得到linearLayoutManager這樣的:

((LinearLayoutManager) mList.getLayoutManager()).scrollToPositionWithOffset(mPositionToScroll, 0); 
+0

謝謝,我會試試看。 – empt

+0

我這樣做,但它仍然沒有效果,第一次只能看到它的滾動tottom它。recycleview有一個標題,並且該項目是Glide的視圖加載 – empt

0

請讓我知道你的方式定義你的recyclerview

+0

code'topLayoutManger = new TopLayoutManager(this,LinearLayoutManager。垂直,假); mRecyclerView.setLayoutManager(topLayoutManger); mRecyclerView.addHeaderView(mVHeader); mRecyclerView.addOnScrollListener(scrollListener); mProductDetailAdapter = new ProductDetailAdapter(getApplicationContext()); mProductDetailAdapter.setListener(this); mRecyclerView.setAdapter(mProductDetailAdapter);' – empt

+0

XML'' – empt

相關問題