2

I have a Layout with structure of following :

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Activites.Settings.ContactsActivity">

    <FrameLayout
        android:id="@+id/fl_contacts"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginTop="5dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tv_mirriom_contacts">

    </FrameLayout>

    some other widgets

</androidx.constraintlayout.widget.ConstraintLayout>

in this frameLayout I show a fragemnt that contains a recyclerView. i am going to scroll all layout not just recyclerView. so i implemented this structure

<androidx.constraintlayout.widget.ConstraintLayout >
<NestedScrollView>
<androidx.constraintlayout.widget.ConstraintLayout >
 <FrameLayout
       android:layout_width="0dp"
        android:layout_height="wrap_content"
 />
 Other widgets
</androidx.constraintlayout.widget.ConstraintLayout >
</NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout >

in this mode scrolling is right but all items of recycler load together and cause app not responding

this is my fragment

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".Activites.Event.Fragments.MirriomContactsFrag">


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_contact"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0"
        tools:listitem="@layout/item_user" />



</androidx.constraintlayout.widget.ConstraintLayout>

Edit

my fragment xml :

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".Activites.Event.Fragments.MirriomContactsFrag">


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_contact"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0"
        tools:listitem="@layout/item_user" />



</androidx.constraintlayout.widget.ConstraintLayout>

main activity:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Activites.Settings.ContactsActivity">

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">



    <FrameLayout
        android:id="@+id/fl_contacts"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tv_mirriom_contacts">

    </FrameLayout>

    <include
        android:id="@+id/app_bar"
        layout="@layout/search_appbar"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView27"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:onClick="deleteSyncedContactsItemClicked"
        android:padding="12dp"
        android:text="@string/delete_synced_contacts"
        android:clickable="true"
        android:background="@drawable/my_ripple"
        android:textColor="@color/colorAccent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/app_bar"
        android:focusable="true" />

    <TextView
        android:id="@+id/textView28"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:padding="12dp"
        android:text="@string/sync_contacts"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView27" />

    <TextView
        android:id="@+id/textView29"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:drawableStart="@drawable/ic_share"
        android:drawablePadding="12dp"
        android:padding="12dp"
        android:onClick="inviteFriendsToMirorimItemClicked"
        android:text="@string/invite_friends_to_mirorim"
        android:textColor="@color/colorAccent"
        android:clickable="true"
        android:background="@drawable/my_ripple"
        app:drawableTint="@color/colorAccent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView28"
        android:focusable="true" />

    <com.example.mirriom.Widget.SwitchButton
        android:id="@+id/swt_sync_contacts"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="12dp"
        app:layout_constraintBottom_toBottomOf="@+id/textView28"
        app:layout_constraintEnd_toEndOf="@+id/textView28"
        app:layout_constraintTop_toBottomOf="@+id/textView27"
        app:sb_checked="true"
        app:sb_checked_color="#77d672"
        app:sb_checkline_width="56dp"
        app:sb_show_indicator="false"
        app:sb_uncheckcircle_width="26dp" />

    <TextView
        android:id="@+id/tv_mirriom_contacts"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="5dp"
        android:onClick="mirriomContactItemClicked"
        android:padding="@dimen/text_clickable_padding"
        android:text="@string/mirriom"
        android:textColor="@color/influencer_text_selection"
        android:textSize="@dimen/default_text_size"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/recycler_contact"
        app:layout_constraintEnd_toStartOf="@+id/tv_all_contacts"
        app:layout_constraintTop_toBottomOf="@+id/textView29" />

    <TextView
        android:id="@+id/tv_all_contacts"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="12dp"
        android:onClick="AllContactItemClicked"
        android:padding="@dimen/text_clickable_padding"
        android:text="@string/all"
        android:textColor="@color/influencer_text_selection"
        android:textSize="@dimen/default_text_size"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/recycler_contact"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView29" />

    <TextView
        android:id="@+id/textView30"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="12dp"
        android:text="@string/contacts"
        android:textColor="@color/text_color"
        android:textSize="@dimen/default_text_size"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="@+id/tv_mirriom_contacts"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/tv_mirriom_contacts" />

        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.core.widget.NestedScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>

1 Answers1

0

Your RecyclerView's layout_height is set to wrap_content, which tells it to inflate all of its items at once and then set its height to the total height of the items with no scrolling (that is, the scrolling is coming only from the parent NestedScrollView). You want to put it outside of the NestedScrollView and set its height to match_parent (or 0dp if it's in a ConstraintLayout with constraints that will size it appropriately), which will tell it to fill the space available. If you want nested scrolling with the RecyclerView for things like a collapsing toolbar, see this question for how to use CoordinatorLayout to accomplish this.

Ryan M
  • 18,333
  • 31
  • 67
  • 74
  • in edit I added my xmls ... please tell what to do to solve my problem ... setting recyclerView macthParent and set scroll behaviour to recycler did not solve problem – Ali Delavari Apr 17 '20 at 22:56
  • What, exactly, are you trying to do, and how are all of the things nested? Why are you trying to put a RecylerView inside a NestedScrollView (which, as I said, you shouldn't do)? The "edit" XML you pasted still has it as `wrap_content`, which is wrong - for that particular case, you probably want to set it to `0dp` to match the constraints (I've added this to my answer). – Ryan M Apr 18 '20 at 00:24
  • the thing that t want to achieve is that instead of scrolling just my RecyclerView i want to scroll whole page not just recycler. adding app:layout_behavior="@string/appbar_scrolling_view_behavior" to my RecyclerView not helped me – Ali Delavari Apr 18 '20 at 05:58