【问题标题】:RecyclerView in NestedScrollView with horizontal-scolling水平滚动的 NestedScrollView 中的 RecyclerView
【发布时间】:2016-09-27 02:02:27
【问题描述】:

我想要这样的结果:

可以水平滚动

但其实像下面这样:

不能显示所有项目,也不能水平布局。

谁能帮帮我?谢谢。其他方式可以在这里达到我想要的结果吗?

【问题讨论】:

  • 看看这里:*.com/editing-help#images,然后编辑或提出一个新问题,并将图像正确放入其中。如果一切正常,请务必检查预览。

标签: android horizontal-scrolling nestedscrollview


【解决方案1】:

您需要将布局管理器添加到 RecylerView。

    LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
    recylcerView.setLayoutManager(layoutManager);

这将使 RecylerView 水平。

【讨论】:

  • 我设置了LinearLayoutManager.HORIZONTAL,但是NestedScrollView中的RecyclerView显示垂直,而不是水平
【解决方案2】:

要将 recyclerView 设置为水平滚动视图,您可以使用 LinearLayoutManager。默认情况下,它设置垂直滚动行为。

LinearLayoutManager layout = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);//0 Horizontal , 1 vertical
recyclerView.setLayoutManager(layout);

在 layout.xml 中

<android.support.v7.widget.RecyclerView
    android:id="@+id/yourRecyclerView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/layout_past_round_header"
    android:layout_centerInParent="true"
    android:overScrollMode="never" />

在你的 NestedScrollView 添加这个

android:fillViewport="true"

【讨论】:

    最近更新 更多