【问题标题】:recyclerview inside horizontalscrollview水平滚动视图内的回收器视图
【发布时间】:2016-06-04 00:48:06
【问题描述】:

如何将垂直回收器视图放入水平滚动视图?

adapter在viewholder绑定数据时,增加item的左边距。

(例如:leftMargin = 位置 * 100)

但水平滚动视图不起作用。 帮帮我~~
对不起,我的英语不好。

我的活动布局.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent">

<HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:scrollbarAlwaysDrawHorizontalTrack="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>
</HorizontalScrollView>
</FrameLayout>

和 list_item .xml

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="8dp"
card_view:cardCornerRadius="2dp">

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/icon"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@drawable/bullet" />
    <CheckBox
        android:id="@+id/check"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>
</android.support.v7.widget.CardView>

【问题讨论】:

  • 为什么要把recycleView放在horrizontalScroll里面?您可以通过使用 RecycleView 来实现另一个目标并使其水平。
  • 谢谢我试试。我认为您的解决方案需要两个适配器。我可以得到更简单的方法吗?

标签: android


【解决方案1】:

如果您想要水平滚动的项目列表,请将LinearLayoutManagerRecyclerView 结合使用。

LinearLayoutManager manager = new LinearLayoutManager(
  this,
  LinearLayoutManager.HORIZONTAL,
  false
);

【讨论】:

  • 谢谢,但我希望 recyclerview 的父视图有水平滚动。
  • 您的用例到底是什么?也许有更好的选择
  • 我的垂直 recyclerview 的项目有左边距。它们的左边距值按位置增加。像这样 -> 列表的索引 * 100 。所以第一个项目的边距为 0,第二个项目的边距为 100 ...所以项目右侧不可见。我想水平滚动以显示他们的右侧。 (看我的照片)谢谢。
猜你喜欢
  • 2017-11-30
  • 1970-01-01
  • 2018-05-08
  • 1970-01-01
  • 1970-01-01
  • 2021-06-08
  • 1970-01-01
  • 2017-01-07
  • 1970-01-01
相关资源
最近更新 更多