【问题标题】:android when recyclerview in a viewpager is scrolled, how to top parent scrollview scrollandroid当滚动viewpager中的recyclerview时,如何顶部父滚动视图滚动
【发布时间】:2018-12-18 06:46:19
【问题描述】:

我提出以下观点。

<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 中的 recyclerview 向上滚动时,如何滚动顶部的 ScrollView。 目前,只有 viewpager 中的 recyclervie 会被滚动。

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

【问题讨论】:

  • 试试 NestedScrollView
  • 您能否详细解释一下您到底想达到什么目标?
  • @Moinkhan 谢谢你的回答,但我应用了 NestedScrollView,但它不起作用
  • 在 nestedScrollView 中应用一些属性,如 fillViewPort、NestedScrollingEnable ...
  • @RudrikPatel 一个viewpager 有两个fragment,每个fraghemt 都有一个recyclerview,当我recyclerview 滚动时,父scrollview 不滚动,只有recycerview 滚动

标签: android scroll android-recyclerview android-viewpager


【解决方案1】:

由于缺少您的代码信息,我不确定这是否能解决您的问题,但是,请尝试一下,如果这能解决您的问题,请告诉我。

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

【讨论】:

  • 我添加了我的代码。我希望当我在 viewpager 中滚动回收器视图时,我想一起滚动父滚动视图(id=layout_scrollview)
  • 因此,当您向上滚动回收站视图时,您希望您的个人资料缩略图布局也向上移动。对吗?
【解决方案2】:

使用下面来阻止 Parent 获取任何事件。

recyclerView.requestDisallowInterceptTouchEvent(true)

当您希望父级拦截子级事件时,将其设置为 false

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

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

【讨论】:

    猜你喜欢
    • 2017-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-08
    • 1970-01-01
    相关资源
    最近更新 更多