简体   繁体   English

android,当在viewpager中滚动recyclerview时,如何使父scrollview滚动到顶部

[英]android when recyclerview in a viewpager is scrolled, how to top parent scrollview scroll

i make the following view. 我提出以下看法。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_gravity="center|right"
        android:gravity="center"
        android:orientation="horizontal">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="@{() -> viewActions.openMore()}"
            android:src="@drawable/btn_my_more" />

    </LinearLayout>

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

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

            <LinearLayout
                android:id="@+id/layout_profile"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="55dp"
                android:gravity="center_horizontal"
                android:orientation="vertical"
                android:visibility="visible">

                <ImageView
                    android:id="@+id/iv_profile_thumbnail"
                    android:layout_width="90dp"
                    android:layout_height="90dp"
                    android:background="@drawable/shape_my_profile_thumbnail"
                    android:scaleType="fitCenter"
                    app:profileThumbnailSrc="@{myProfile.profileUrl}" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="6dp"
                    android:text="@{myProfile.urlId}"
                    android:textColor="@color/black"
                    android:textSize="23dp"
                    android:textStyle="bold" />
            </LinearLayout>
            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager_my"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="@dimen/gnb_height" />
        </LinearLayout>
    </ScrollView>
</LinearLayout>

The viewpager has two fragment with recyclerview. viewpager有两个带有recyclerview的片段。

when ia recyclerview in a viewpager scroll up, how to scroll the top ScrollView. 当viewpager中的ia recyclerview向上滚动时,如何滚动顶部的ScrollView。 in current, only recyclervie in a viewpager is scrolled. 当前,仅滚动viewpager中的recyclervie。

if you know how to solve, please answer my question. 如果您知道如何解决,请回答我的问题。 thank you very much 非常感谢你

I am not sure if this will solve your problem or not because of the lack of your code information but, please try this and let me know if this resolves your issue. 由于缺少您的代码信息,我不确定这是否可以解决您的问题,但是请尝试一下,让我知道这是否可以解决您的问题。

    recyclerView.setHasFixedSize(true);
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext(),LinearLayoutManager.VERTICAL, false);
    layoutManager.setAutoMeasureEnabled(true);
    recyclerView.setNestedScrollingEnabled(false);
    recyclerView.setLayoutManager(layoutManager);

use below to stop Parent getting any event. 在下面使用以阻止家​​长收到任何事件。

 recyclerView.requestDisallowInterceptTouchEvent(true) 

set it to false when you want parent to Intercept event's of child. 当您希望父项拦截孩子的事件时,请将其设置为false

if you want to stop scrolling in recycler is a special case : 如果要停止在回收站中滚动是一种特殊情况:

override fun onTouchEvent(event: MotionEvent?): Boolean {
 //special case condition
   if(x==y&& event.action== MotionEvent.ACTION_DOWN){
     return false
  }
}

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

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