1. Are you ready for the Galaxy S20? Here is everything we know so far!

RecyclerView in ConstraintLayout OnScroll Issue

Discussion in 'Android Development' started by shubham1835, Feb 21, 2021.

  1. shubham1835

    shubham1835 Lurker
    Thread Starter

    My RecyclerView in constraint layout is not working as expected. RecyclerView Item is getting scrolled to top and alignment of items are getting changed.
    I have 3 Layouts in constarintLayout Blue is the top layout, Yellow is the middle Layout (Recycler View), Green is the End Layout.

    upload_2021-2-22_2-1-11.png
    Above one is the layout design below is the xml code.
    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout 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">

    <FrameLayout
    android:id="@+id/startLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toTopOf="@id/recyclerViewFrameLayout"
    app:layout_constraintLeft_toRightOf="parent"
    android:background="#372CD3"
    app:layout_constraintRight_toLeftOf="parent">
    <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
    </FrameLayout>

    <FrameLayout
    android:id="@+id/recyclerViewFrameLayout"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    android:background="#fff123"
    app:layout_constraintTop_toBottomOf="@+id/startLayout">

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

    <FrameLayout
    android:id="@+id/endLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    android:background="#abc123"
    app:layout_constraintStart_toStartOf="parent">
    <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
    </FrameLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>

    Below one is the app screenshot
    upload_2021-2-22_2-3-48.png

    Below one is the screenshot after scrolled.
    upload_2021-2-22_2-4-49.png
     



    1. Download the Forums for Android™ app!


      Download

       
  2. Unforgiven

    Unforgiven ...eschew obfuscation...
    Moderator

    Welcome to AndroidForums.com. :) To make your code more readable and make it easier for the folks that can help, well, help, you should use code tags.

    Code Tag Usage:
    [code]Line 1
    Line 2
    Line 3
    Maintains white space
    Doesn't turn :) into emoji
    etc...
    [/code]
    Code (Text):
    1. Line 1
    2. Line 2
    3. Line 3
    4. Maintains white space
    5. Doesn't turn :) into emoji
    6. etc...
    7.  
    Good luck!! :)
     
Loading...

Share This Page

Loading...