0

i have a recycler view which contains a lot of posts. while i scroll the recyclerview my frame layout doesn't scroll. it is fixed like a navigation bar. I want it to scroll as if it was part of the recyclerview. Here is my layout:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    tools:context=".HomePageFragment">

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

        <FrameLayout
            android:id="@+id/status_frame"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"></FrameLayout>

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

   </LinearLayout>
</ScrollView>

i tried using nestedScrollView but it adds extra empty posts. I dont know why.

enter image description here

My frameLayout is the status part. which is another recyclerview itself.while scrolling the posts the statuspart doesn't scroll.

Qahar
  • 69
  • 9

1 Answers1

0

In order for status part to scroll with posts in the recyclerview, status part should also be an item in the recyclerview, so you need recyclerview with multiple view types for this case. Plase read: How to create recyclerview with multiple view types.

Just remove the Framelayout it's not necessary, when using recyclerviews with multiple view types.

Minor improvements

Remove the outer scrollview its unnecessary, since recyclerview by default is scrollable.

Edit:

In order for status part to be scrollable horizontally, status part item layout should contain a recyclerview where LinearLayoutManager orientation set to horizontal. Remember to implement the adapter class for the horizontal recyclerview also.

For you to get started with recyclerview with multiple view types, you may look at this tutorial.


You may also use library like Epoxy in this case.

user158
  • 12,852
  • 7
  • 62
  • 94
  • The status part is another recyclerview which scrolls horizontally. while the post part scrolls vertically. is it possible to do using what you suggest? – Qahar Sep 07 '19 at 17:55
  • yes its possible, updated the answer. please make sure to upvote and accept the answer if it satisfy you. You may look at [this tutorial](https://www.youtube.com/watch?v=hVJpWSalzbo) – user158 Sep 08 '19 at 10:30