【问题标题】:How to create list item scroll-able in Recycler View?如何在回收站视图中创建可滚动的列表项?
【发布时间】:2018-03-03 04:52:26
【问题描述】:

我创建了回收站视图。一切正常。我希望我的列表项根据屏幕展开而不是包装内容。它应该是水平滚动列表项。

我的回收站视图 XML:

  <android.support.v7.widget.RecyclerView
      android:id="@+id/recyclerView2"
      android:layout_width="match_parent"
      android:layout_marginTop="10dp"
      android:layout_height="wrap_content"
      app:layout_behavior="@string/appbar_scrolling_view_behavior" />

这是我设置 Recyler View 的代码。

RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());


    recyclerView2.setLayoutManager(mLayoutManager2);
    recyclerView2.setItemAnimator(new DefaultItemAnimator());

【问题讨论】:

    标签: android android-recyclerview horizontal-scrolling


    【解决方案1】:

    你改变回收站视图的高度,如下所示..

     <android.support.v7.widget.RecyclerView
      android:id="@+id/recyclerView2"
      android:layout_width="match_parent"
      android:layout_marginTop="10dp"
      android:layout_height="match_parent"
      app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    

    【讨论】:

    • 是的,这不是他们要的。他们在谈论水平滚动的项目。
    • 然后回收器视图设置滚动视图,如 mLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    • 不,项目单独水平滚动,而不是整个RecyclerView
    • 对不起先生,但 mLayoutManager 没有任何带有“setOrientation”的方法。
    • Horizo​​ntalScrollView 帮助了我。我在列表项布局上添加了 Horizo​​ntalScrollView,它给了我想要的结果。也会尝试你的答案。
    【解决方案2】:

    据我了解,您需要一个垂直滚动的回收器视图,并且回收器视图中的每个项目都需要水平滚动。 为此,您需要回收站视图的每个项目本身都是回收站视图。网上有教程,您可以看看这个Google Play Store Replica

    【讨论】:

    • 对不起先生,但 mLayoutManager 没有任何带有“setOrientation”的方法
    • @ArmanReyaz 我已经编辑了我的答案,请查看链接并让我知道这是否是您要查找的内容。
    • @ArmanReyaz 如果这就是您正在寻找的内容,那么简单的谷歌搜索 android horizontal scroll in vertical recycler view 应该会为您提供足够多的内容来创建您想要的列表。
    • 感谢先生的帮助,但 Horizo​​ntalScrollView 帮助了我。我在列表项布局上添加了 Horizo​​ntalScrollView,它给了我想要的结果。
    • 如果您尝试在以水平方式滚动的项目内回收视图,那么您需要在绑定到回收器视图的适配器布局中定义滚动视图。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-22
    • 1970-01-01
    • 2019-11-05
    • 1970-01-01
    相关资源
    最近更新 更多