水平滚动视图内的recyclerview [英] recyclerview inside horizontalscrollview

查看:151
本文介绍了水平滚动视图内的recyclerview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何将vertical recyclerview放入horizo​​ntalScrollview中?

how can i put vertical recyclerview inside horizontalScrollview ?

当适配器将数据绑定到Viewholder时,项目的左边距增加.

when adapter binds data at viewholder, item's left margin is increase.

(例如:leftMargin =位置* 100)

(ex : leftMargin = position * 100)

但是在horizo​​ntalScrollview中不起作用. 帮帮我~~
对不起,我的英语不好.

but doesn't work horizontalScrollview. help me ~~
sorry for my bad english.

我的活动布局.xml

my activity layout .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

and 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>

推荐答案

如果想要的是水平滚动项的列表,请在RecyclerView中使用LinearLayoutManager.

If what you want is a list of items that scroll horizontally, use LinearLayoutManager with your RecyclerView.

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

这篇关于水平滚动视图内的recyclerview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆