0

So,

I have a layout.xml file which contains a Recycler View. Now, what I want is, I added two image Views on top of this Recycler View but I want those ImageViews to scroll with the RecyclerView as well.

I just wanted to ask, is this possible to do? And if yes, how can I achieve this?

<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/content_parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <include
        android:id="@+id/header_bar"
        layout="@layout/section_header" />

    
    <ImageView-1> 
    <ImageView-2> 

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/category_grid"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:paddingHorizontal="@dimen/category_grid_edge_space"
        android:paddingTop="@dimen/category_grid_padding_top"
        android:scrollbarSize="@dimen/grid_padding"
        android:scrollbarStyle="outsideOverlay"
        android:scrollbarThumbVertical="?android:attr/textColorSecondary"
        android:scrollbars="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
hans
  • 147
  • 2
  • 8
  • Put ImageViews and RecyclerView in a NestedScrollView. – Abdullah Javed Feb 17 '23 at 13:24
  • What you need is to have those image views as list items with different view types https://stackoverflow.com/questions/26245139/how-to-create-recyclerview-with-multiple-view-types – Ahmed Hegazy Feb 17 '23 at 13:25
  • Use a single recycler view in the layout & use Concat Adapter https://developer.android.com/reference/androidx/recyclerview/widget/ConcatAdapter. – Malik Bilal Feb 17 '23 at 14:51

2 Answers2

0

Put your RecycleView in NestedScrollView

<android.support.v4.widget.NestedScrollView
  android:layout_width="match_parent"
  android:layout_height="wrap_content">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <include
        layout="@layout/your_header"/>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/category_grid"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>

</android.support.v4.widget.NestedScrollView>

also don't forget to disabled NestedScrolling for RecyclerView

myRecyclerView.setNestedScrollingEnabled(false);

OR

Add those views as a header. Here is a good guide on how to add a custom item view: https://medium.com/androiddevelopers/get-ahead-using-headers-in-recyclerview-2909a69b19

Oleg
  • 591
  • 5
  • 14
0

https://github.com/masudias/RecyclerView-with-Header-and-Footer

You can use header and footer i

B A
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Alan Bosco Feb 23 '23 at 10:41