[英]Scrolling issue with RecyclerView in CoordinatorLayout
I have issue with scrolling in my code .. here is my xml :-我在我的代码中滚动有问题.. 这是我的 xml :-
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@color/colorThemeDark"
android:fitsSystemWindows="true"
android:stateListAnimator="@drawable/appbar_always_elevated"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:collapsedTitleGravity="left"
app:contentScrim="@color/colorThemeDark"
app:expandedTitleGravity="center|bottom"
app:expandedTitleTextAppearance="@style/ExpandedAppBar"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/circleView"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
android:layout_gravity="center_vertical|center_horizontal"
android:src="@drawable/main_logo"
app:layout_collapseMode="none" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#323642"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RelativeLayout
android:id="@+id/firstText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:paddingLeft="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="What you learn today?"
android:textColor="@color/colorWhite"
android:textStyle="bold" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/catBoxes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/firstText"
android:layout_marginTop="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp" />
<RelativeLayout
android:id="@+id/secondText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/catBoxes"
android:paddingLeft="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Recommended for you"
android:textColor="@color/colorWhite"
android:textStyle="bold" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/catMenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/secondText"
android:layout_marginTop="5dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior" </android.support.v7.widget.RecyclerView>
</RelativeLayout></android.support.design.widget.CoordinatorLayout>
I have two different recyclerView in single Activity.as in my code , i take root element as CoordinatorLayout.我在我的代码中的单个 Activity.as 中有两个不同的 recyclerView,我将根元素作为 CoordinatorLayout。 i add two RecyclerView in my code.when i scroll my recyclerview it scroll only first recyclerView and second RecyclerView scroll below first recyclerview.
我在我的代码中添加了两个 RecyclerView。当我滚动我的 recyclerview 时,它只滚动第一个 recyclerView,第二个 RecyclerView 滚动到第一个 recyclerview 下方。 but i want to both recyclerView scroll at same time when i scroll up my screen.
但是当我向上滚动屏幕时,我想同时滚动 recyclerView。
Gif with my problem.我的问题的GIF。 Green boxes scrolled but i want to stop this green boxes scrolling
绿色框滚动,但我想阻止这个绿色框滚动
When you have two recycler view in a view and you want them to use all the space, you need to use NestedScrollView .当您在一个视图中有两个回收器视图并且您希望它们使用所有空间时,您需要使用NestedScrollView 。
Your code will be the following:您的代码如下:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#323642"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RelativeLayout
android:id="@+id/firstText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:paddingLeft="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="What you learn today?"
android:textColor="@color/colorWhite"
android:textStyle="bold" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/catBoxes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/firstText"
android:layout_marginTop="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp" />
<RelativeLayout
android:id="@+id/secondText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/catBoxes"
android:paddingLeft="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Recommended for you"
android:textColor="@color/colorWhite"
android:textStyle="bold" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/catMenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/secondText"
android:layout_marginTop="5dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
And in your code, use this in both recycler view:在您的代码中,在两个回收站视图中都使用它:
LayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setAutoMeasureEnabled(true);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setNestedScrollingEnabled(false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.