简体   繁体   English

如何禁用RecyclerView滚动使布局侦听其ScrollView父级?

[英]How to disable RecyclerView scrolling to make the layout listen its ScrollView parent?

I'm trying to put a RecyclerView , inside a ScrollView . 我正在尝试在ScrollView放置一个RecyclerView But the ScrollView doesn't scrolls and the RecyclerView does but I don't want it to... What can I do? 但是ScrollView不会滚动而且RecyclerView会滚动但我不希望它...我该怎么办?

I tried with this class https://stackoverflow.com/a/30222721/4864104 and in fact the RecyclerView doesn't scroll anymore, but neither does the ScrollView . 我试过这个类https://stackoverflow.com/a/30222721/4864104 ,实际上RecyclerView不再滚动,但ScrollView也没有。

Any help to make the ScrollView work even with the disabled RecyclerView ? 任何帮助使ScrollView即使使用已禁用的RecyclerView也可以工作? Thanks in advance. 提前致谢。

This is my layout: 这是我的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="jahirfiquitiva.projects.activities.DeveloperActivity">

<include
    android:id="@+id/toolbar"
    layout="@layout/toolbar" />

<ScrollView
    android:id="@+id/osv"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/toolbar"
    android:fillViewport="true"
    android:gravity="center"
    android:overScrollMode="never">

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

        <ImageView
            android:id="@+id/photoJahir"
            android:layout_width="144dp"
            android:layout_height="144dp"
            android:layout_gravity="center"
            android:gravity="center" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:lineSpacingMultiplier="1.2"
            android:paddingBottom="@dimen/lists_padding"
            android:paddingTop="@dimen/lists_padding"
            android:text="@string/developer_bio"
            android:textSize="@dimen/abc_text_size_subtitle_material_toolbar" />

        <View
            android:layout_width="match_parent"
            android:layout_height="@dimen/dividers_about_section"
            android:alpha="0.3"
            android:background="@color/primary" />

        <RecyclerView
            android:id="@+id/buttonsGrid"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingBottom="@dimen/lists_padding"
            android:paddingTop="@dimen/lists_padding" />

        <View
            android:layout_width="match_parent"
            android:layout_height="@dimen/dividers_about_section"
            android:alpha="0.3"
            android:background="@color/primary" />

        <View
            android:layout_width="match_parent"
            android:layout_height="72dp" />

    </LinearLayout>

</ScrollView>

您可以通过将滚动视图更改为NestedScrollView并设置recyclerView.setNestedScrollingEnabled(false)来轻松实现它具有最高性能并且无需覆盖布局管理器。

I think you just need to wrap recyclerView so that other views can be visible. 我认为您只需要包装recyclerView以便可以看到其他视图。 Just use this library so that you can adjust recycler view height coz linearLayoutManager as per now matches height to match parent. 只需使用此库,以便您可以调整回收器视图高度coz linearLayoutManager现在匹配高度以匹配父级。 https://github.com/serso/android-linear-layout-manager https://github.com/serso/android-linear-layout-manager

it not as simple as you think. 它并不像你想象的那么简单。 when you use tow scrollble element inside each other you are in hot water! 当你在彼此内部使用拖动滚动元素时,你处于热水中! you should calculate the Recycler item height and then find the whole recycler height. 您应该计算Recycler项目的高度,然后找到整个回收者的高度。 look at below link, I explain completely this problem. 看下面的链接,我完全解释了这个问题。

Use RecyclerView indie ScrollView with flexible recycler item height 使用RecyclerView独立ScrollView,灵活的回收物项目高度

I hope it help you 我希望它对你有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM