1

此代码按预期工作:

    LinearLayoutManager layoutManager = new LinearLayoutManager(this,
            LinearLayoutManager.VERTICAL, false);
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.scrollToPosition(2);

定位和滚动是垂直的,显示第三项。

现在,如果在上面的代码VERTICAL中替换为HORIZONTAL,项目将水平显示并且滚动是水平的(如预期的那样),但setScrollToPosition(2)不再起作用。

如何scrollToPosition搭配HORIZONTAL LinearLayoutManager

下面提到了我的 XML 文件:

< android.support.v7.widget.RecyclerView
    android:id="@+id/rvPosters"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingTop="4dp"
    android:paddingBottom="4dp" >
4

0 回答 0