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

非 Y 不嫁゛ 提交于 2020-01-11 06:51:49

问题


I'm trying to put a RecyclerView, inside a ScrollView. But the ScrollView doesn't scrolls and the RecyclerView does but I don't want it to... What can I do?

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.

Any help to make the ScrollView work even with the disabled 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>


回答1:


You could easily achieve it by changing your scroll view into a NestedScrollView and setting recyclerView.setNestedScrollingEnabled(false) Has the highest performance and No need to override the layout manager.




回答2:


I think you just need to wrap recyclerView so that other views can be visible. Just use this library so that you can adjust recycler view height coz linearLayoutManager as per now matches height to match parent. https://github.com/serso/android-linear-layout-manager




回答3:


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. look at below link, I explain completely this problem.

Use RecyclerView indie ScrollView with flexible recycler item height

I hope it help you



来源:https://stackoverflow.com/questions/31421496/how-to-disable-recyclerview-scrolling-to-make-the-layout-listen-its-scrollview-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!