[英]buttons for scrolling left and right in HorizontalScrollView in android
[英]Scrolling recyclerview using buttons right and left
您可以使用一個變量來跟蹤RecyclerView的當前顯示位置,在下面的代碼片段中將其命名為“ currentPosition”
如果要導航到下一個項目,則按以下步驟遞增:
private void scrollToNext() {
if ((recyclerView.getLayoutManager()) != null) {
((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(currentPosition++, 0);
}
}
您可以使用RelativeLayout
或自定義布局代替LinearLayout
; 根據您在RecyclerView
同樣,如果要上一個減小它
private void scrollToPrevious() {
if ((recyclerView.getLayoutManager()) != null) {
((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(currentPosition--, 0);
}
}
您可以使用“ 下一步”按鈕:
mRecyclerView.getLayoutManager().scrollToPosition(linearLayoutManager.findLastVisibleItemPosition() + 1);
對於上一個按鈕:
mRecyclerView.getLayoutManager().scrollToPosition(linearLayoutManager.findFirstVisibleItemPosition() - 1);
看這個
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.