繁体   English   中英

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

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

我提出以下看法。

<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>

viewpager有两个带有recyclerview的片段。

当viewpager中的ia recyclerview向上滚动时,如何滚动顶部的ScrollView。 当前,仅滚动viewpager中的recyclervie。

如果您知道如何解决,请回答我的问题。 非常感谢你

由于缺少您的代码信息,我不确定这是否可以解决您的问题,但是请尝试一下,让我知道这是否可以解决您的问题。

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

在下面使用以阻止家​​长收到任何事件。

 recyclerView.requestDisallowInterceptTouchEvent(true) 

当您希望父项拦截孩子的事件时,请将其设置为false

如果要停止在回收站中滚动是一种特殊情况:

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