我想实现一个布局,其中包含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>
问题:我可以滚动,直到滚动型
东西:
在滚动型
(现在滚动型
包含 RecyclerView ) - 可以看到该卡,直到 RecyclerView
在最初的想法是要实现这个的ViewGroup
使用 RecyclerView
而不是滚动型
,其中它的一个意见类型是 CardView
,但我得到了完全相同的结果与滚动型
card view inside the ScrollView
(now ScrollView
contains RecyclerView
) - can see the card up until the RecyclerView
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;