小编Ste*_*hen的帖子

NestedScrollview内的Recyclerview scrollTo位置不起作用

当我在NestedScrollView中使用RecyclerView时,我使用scrollTo()固定位置,它不起作用.

(rlv_brandWithLetter.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(index, 0)
rlv_brandWithLetter.smoothScrollToPosition(index)
Run Code Online (Sandbox Code Playgroud)

我读了源代码NestedScrollView,该方法scrollTo()已执行.

@Override
public void scrollTo(int x, int y) {
    if (getChildCount() > 0) {
        View child = getChildAt(0);
        x = clamp(x, getWidth() - getPaddingRight() - getPaddingLeft(), child.getWidth());
        y = clamp(y, getHeight() - getPaddingBottom() - getPaddingTop(), child.getHeight());
        if (x != getScrollX() || y != getScrollY()) {
            super.scrollTo(x, y);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

x != getScrollX() || y != getScrollY()总是回来false,这是我发现的线索.

有没有人遇到过这个问题?

android android-recyclerview android-nestedscrollview

6
推荐指数
0
解决办法
366
查看次数