Instagram의 필터 레이아웃이 작동하는 것과 비슷한 레이아웃을 만들려고합니다. 기본적으로 필터를 선택하면 선택한 항목으로 스크롤되어 더 많은 필터가 있음을 보여줍니다.LinearLayoutManager 부드러운 스크롤이 잘못된 위치로 점프합니다.
나는 현재 여기 내 수평 RecyclerView
에 대한 사용자 지정 LinearLayoutManager
구축을 위해 노력하고 있어요 : 스크롤 의도대로 작품을 왼쪽하지만 난 잘 스크롤있을 때 그냥 목록의 끝으로 이동 보인다
public class LinearLayoutSnapManager extends LinearLayoutManager {
private int mCurrentPos = 0;
public LinearLayoutSnapManager(Context context) {
super(context);
}
public LinearLayoutSnapManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
public LinearLayoutSnapManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public void snap(RecyclerView rv, int position) {
if (mCurrentPos == position) {
// No move
return;
}
boolean goingRight = true;
if (position < mCurrentPos) {
goingRight = false;
}
mCurrentPos = position;
smoothScrollToPosition(rv, new RecyclerView.State(), goingRight ? getScrollRightPos(): getScrollLeftPos());
}
private int getScrollLeftPos() {
int newPos = mCurrentPos - 1;
return (newPos > 0) ? newPos : 0;
}
private int getScrollRightPos() {
return mCurrentPos + 1;
}
}
newItem + 1과 비교할 때 왜 그런 일이 발생하는지 알 수 없습니다.
더 많은 코드를 게시 할 수 있습니까? 그 방법을 사용하는 방법은 무엇입니까? 당신의 논리는 괜찮은 것 같지만 잘못된 순간에 위치를 전달할 수도 있습니다. 즉, – FabioR
getScrollRightPos가 호출 될 때 오래된 (업데이트되지 않은) 위치가 mCurrentPos로 전달되어서 OLD 위치 + 1 (리사이클 러뷰의 끝 부분에있을 수도 있습니다.) 또한, 현재 항목에 인접하지 않은 항목을 클릭하면 스크롤이 문제가되는 것입니까? – FabioR
누가'snap()'을 호출하나요? 'int position'이 어디서 오는가? – g4s8