简体   繁体   English

如何在父级(ScrollView)完全滚动之前禁用子级(RecyclerView)滚动

[英]How to disable child(RecyclerView) scrolling before parent(ScrollView) has completely scrolled

I have a RecyclerView inside a ScrollView. 我在ScrollView中有一个RecyclerView。 When I try to scroll to bottom, the RecyclerView(child element) scrolls to bottom before the parent starts scrolling. 当我尝试滚动到底部时,在父级开始滚动之前,RecyclerView(子元素)会滚动到底部。 But what I want it, the parent should scroll completely before child starts scrolling. 但是我想要的是,在孩子开始滚动之前,父母应该完全滚动。 Here is my layout file. 这是我的布局文件。 Can someone please guide me how can I achieve this? 有人可以指导我如何实现这一目标吗?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/user_activity_linear_layout">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="400dp"
            android:id="@+id/blank_layout"
            android:orientation="vertical">
        </LinearLayout>

        <android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/recently_watched_recycler_view"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="400dp"
            android:id="@+id/blank_layout"
            android:orientation="vertical">
        </LinearLayout>

    </LinearLayout>

</ScrollView>

</RelativeLayout>

Disable RecyclerView. 禁用RecyclerView。 Extend scrollview so that you will know when ot has reached bottom as bellow. 扩展scrollview,以便您可以知道ot何时到达底部。

public class myScrollView extends ScrollView
{
    public myScrollView(Context context)
    {
        super(context);
    }
    public myScrollView(Context context, AttributeSet attributeSet)
    {
        super(context,attributeSet);
    }

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt)
{
    View view = (View)getChildAt(getChildCount()-1);
    int d = view.getBottom();
    d -= (getHeight()+getScrollY());
    if(d==0)
    {
        //you are at the end of the list in scrollview 
        //do what you wanna do here
    }
    else
        super.onScrollChanged(l,t,oldl,oldt);
}

} }

Once your scrollViewReaches bottom enable recyclerView. 一旦您的scrollViewReaches底部启用recyclerView。 Give it a go. 搏一搏。 If you are not able to achieve what you desire using this method let me know. 如果您无法使用此方法实现您的期望,请告诉我。

Just use NestedScrollView - it supports having nested scrolling enabled views (such as RecyclerView ) inside of it. 只需使用NestedScrollView-它支持在其中启用嵌套滚动启用的视图(例如RecyclerView )。 Make sure you are using Support Library 23.2 , which allows RecyclerView to measure itself based on its contents. 确保您使用的是Support Library 23.2 ,该允许RecyclerView根据其内容对其自身进行度量。

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

相关问题 如何禁用RecyclerView滚动使布局侦听其ScrollView父级? - How to disable RecyclerView scrolling to make the layout listen its ScrollView parent? 嵌套的 RecyclerView。 如何防止父 RecyclerView 在子 RecyclerView 滚动时滚动? - Nested RecyclerView. How to prevent parent RecyclerView from getting scrolled while child RecyclerView is scrolling? android,当在viewpager中滚动recyclerview时,如何使父scrollview滚动到顶部 - android when recyclerview in a viewpager is scrolled, how to top parent scrollview scroll 禁用RecyclerView滚动,因此scrollview CHILD可以滚动 - Disable RecyclerView scrolling, so scrollview CHILD can scroll 如何禁用父子recyclerview(嵌套recyclerview)的点击/触摸事件但滚动需要工作 - How to disable the click/touch events for parent and child recyclerview(nested recyclerview) but scrolling needs to work ScrollView 不作为父级滚动,RelativeLayout 作为子级滚动 - ScrollView not scrolling as parent and RelativeLayout as child ScrollView不能完全滚动到子视图 - Scrollview not scrolling to the child-views completely 如何禁用ScrollView滚动? - How to disable ScrollView scrolling? 在子Recyclerview android中禁用滚动 - Disable Scrolling in child Recyclerview android 启用子ScrollView时禁用父ScrollView - Disable parent ScrollView when child ScrollView is enabled
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM