RecyclerView内滚动型不工作 [英] RecyclerView inside ScrollView is not working

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

问题描述

我想实现一个布局,其中包含RecyclerView和滚动型,在相同的布局。

I'm trying to implement a layout which contains RecyclerView and ScrollView at the same layout.

布局模板:

<RelativeLayout>
    <ScrollView android:id="@+id/myScrollView">
       <unrelated data>...</unrealated data>
    </ScrollView>

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="id/myScrollView
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
        >
            <TextView
                ...
            />
            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/my_recycler_view"
            />
        </LinearLayout>
    </android.support.v7.widget.CardView>
</RelativeLayout>

问题:我可以滚动,直到滚动型

东西:

  1. 滚动型(现在滚动型包含 RecyclerView ) - 可以看到该卡,直到 RecyclerView
  2. 在最初的想法是要实现这个的ViewGroup 使用 RecyclerView 而不是滚动型,其中它的一个意见类型是 CardView ,但我得到了完全相同的结果与滚动型
  1. card view inside the ScrollView (now ScrollView contains RecyclerView) - can see the card up until the RecyclerView
  2. initial thought was to implement this viewGroup using RecyclerView instead of ScrollView where one of it's views type is the CardView but i got the exact same results as with the ScrollView

非常感谢您的时间和帮助

Thanks a lot for your time and help

罗伊

推荐答案

虽然建议

您永远不应该把一个滚动视图内的另一个滚动视图

you should never put a scrollable view inside another scrollable view

是一个中肯的意见,但是,如果你设置的回收视图固定高度就应该很好地工作。

Is a sound advice, however if you set a fixed height on the recycler view it should work fine.

如果您知道的适配器项目布局的高度,你可以只计算RecyclerView的高度。

If you know the height of the adapter item layout you could just calculate the height of the RecyclerView.

int viewHeight = adapterItemSize * adapterData.size();
recyclerView.getLayoutParams().height = viewHeight;

这篇关于RecyclerView内滚动型不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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