RecyclerView not scrolling inside NestedScrollView - java

I'm designing a complex UI that has a NestedScrollView as a parent and inside it, there is a RecyclerView. Now the problem is that I'm not able to scroll the items inside the RecyclerView.
Things I've tried
Replacing ScrollView with NestedScrollView
Enabling android:fillViewport="true"
Disabling NestedScrolling of RecyclerView
<?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=".screens.StudentPreview">
<androidx.cardview.widget.CardView
android:id="#+id/toolbarCV"
android:layout_width="match_parent"
android:layout_height="130dp"
android:translationY="-45dp"
app:cardCornerRadius="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1641A2">
<ImageView
android:id="#+id/menuIV"
android:layout_width="23dp"
android:layout_height="23dp"
android:layout_gravity="center"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:src="#drawable/ic_home"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.7" />
<TextView
android:id="#+id/featureName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:fontFamily="#font/poppins_light"
android:text="Student Preview"
android:textColor="#fff"
android:textSize="22sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.75" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.core.widget.NestedScrollView
android:id="#+id/studentPreviewNSV"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="90dp"
android:fillViewport="true"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:id="#+id/avatarCV"
android:layout_width="60dp"
android:layout_height="60dp"
app:cardBackgroundColor="#color/colorPrimaryDark"
app:cardCornerRadius="40dp"
app:cardElevation="0dp"
app:layout_constraintBottom_toBottomOf="#+id/studentDetailsCL"
app:layout_constraintEnd_toStartOf="#+id/studentDetailsCL"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/studentDetailsCL">
<ImageView
android:id="#+id/avatarIV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:visibility="gone"
tools:src="#drawable/avatar_sample" />
<TextView
android:id="#+id/nameInitialTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/montserrat"
android:textColor="#FFF"
android:textSize="24sp"
android:textStyle="bold"
android:visibility="gone"
tools:text="AK"
tools:visibility="visible" />
</androidx.cardview.widget.CardView>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/studentDetailsCL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/avatarCV"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/studentNameTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/montserrat"
android:textColor="#000"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Akrit Khanna" />
<TextView
android:id="#+id/classNameTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/montserrat"
android:textColor="#000"
android:textSize="15sp"
app:layout_constraintStart_toStartOf="#+id/studentNameTV"
app:layout_constraintTop_toBottomOf="#+id/studentNameTV"
tools:text="Class 8th A" />
<TextView
android:id="#+id/lastLoggedTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:fontFamily="#font/raleway"
android:textColor="#000"
android:textSize="15sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="#+id/classNameTV"
app:layout_constraintTop_toBottomOf="#+id/classNameTV"
tools:text="Last Logged: 30-01-2020" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.cardview.widget.CardView
android:id="#+id/classEnrollCV"
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
app:cardBackgroundColor="#F5F5F5"
app:cardCornerRadius="18dp"
app:cardElevation="3dp"
app:layout_constraintEnd_toStartOf="#+id/courseEnrollCV"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/detailsGL">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/classEnrollCountTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/raleway"
android:textColor="#000"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/classEnrollTVContainerFL"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="1" />
<FrameLayout
android:id="#+id/classEnrollTVContainerFL"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#D0D9EC"
app:layout_constraintBottom_toBottomOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/raleway"
android:text="Classes Enrolled"
android:textColor="#1641A2"
android:textSize="18sp" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/courseEnrollCV"
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:cardBackgroundColor="#F5F5F5"
app:cardCornerRadius="18dp"
app:cardElevation="3dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/classEnrollCV"
app:layout_constraintTop_toTopOf="#+id/detailsGL">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/courseEnrollCountTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/raleway"
android:textColor="#000"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/courseEnrollTVContainerFL"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="1" />
<FrameLayout
android:id="#+id/courseEnrollTVContainerFL"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#D0D9EC"
app:layout_constraintBottom_toBottomOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/raleway"
android:text="Courses Enrolled"
android:textColor="#1641A2"
android:textSize="18sp" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/detailsGL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="90dp" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/reportCL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="#F5F5F5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/classEnrollCV">
<Spinner
android:id="#+id/classOrTermSpinner"
style="#style/Base.Widget.AppCompat.Spinner.Underlined"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintEnd_toStartOf="#+id/courseSpinner"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Spinner
android:id="#+id/courseSpinner"
style="#style/Base.Widget.AppCompat.Spinner.Underlined"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/classOrTermSpinner"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/reportRV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/courseSpinner" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

Use a NestedScrolView and add this to your RecyclerView:
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setHasFixedSize(false);
Or this to the XML:
android:nestedScrollingEnabled="false"
Also it might help to add orientation to the recyclerView:
android:orientation="vertical"

Wrap all the views present inside NestedScrollView into a RelativeLayout. For ex,
<androidx.core.widget.NestedScrollView
android:id="#+id/studentPreviewNSV"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="90dp"
android:fillViewport="true"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- your remaining code -->
</androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>

I managed to fix this problem by adding android:layout_marginBottom="100dp"
I think this was happening because I gave android:layout_marginTop="90dp" to my NestedScrollView and due to that RecyclerView was assuming that all the items are visible on the screen so there is no need for scrolling. (Correct me if I'm wrong)
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/reportRV"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/courseSpinner"
tools:listitem="#layout/report_list_layout"
android:orientation="vertical"
android:layout_marginBottom="100dp"/>

Related

how to scroll up auto in scroll view with kotlin

I making a question app the questions page should be scrolling up when a question have an answer . How can I make this .e.g I want when an question have answer 100px scrolling up . How can I make thnks
`
<RelativeLayout 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="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" tools:context=".Screens.GamePlayFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/gameplay_background"
android:orientation="vertical" >
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView5"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginTop="-5dp"
android:layout_marginBottom="-5dp"
android:src="#drawable/gameapptop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="120dp"
android:layout_height="70dp"
android:layout_marginTop="-15dp"
android:src="#drawable/placeofcountdown_game_screen"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imageViewCounterIcon"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_marginTop="5dp"
android:paddingBottom="30dp"
android:layout_marginLeft="5dp"
android:src="#drawable/gameovercountericon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Chronometer
android:id="#+id/textViewCounter"
android:layout_width="wrap_content"
android:layout_height="55dp"
android:layout_marginTop="5dp"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/imageViewCounterIcon"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginRight="10dp"
android:text="2/17"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<ScrollView
android:layout_width="match_parent"
android:id="#+id/linearLayoutGame"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="0dp"
>
<!--Question 1 -->
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView9"
android:layout_width="400dp"
android:layout_height="220dp"
android:layout_marginTop="-2dp"
android:src="#drawable/placeofquestion3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/questionLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="#+id/qRoof1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/q1"
android:layout_width="270dp"
android:layout_height="120dp"
android:src="#drawable/q1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
`
How can I make this .e.g I want when an question have answer 100px scrolling up . How can I make thnks

Multiples imagesView with text in a ScrollView

I'm making a soundbox for me and my friends in android studio.
I've got a simple Scroll view, that I filled up with multiple constraintLayout that each contains 2 imageView with each of having a line of text under it.
The problem is that when I run the app, I only see the 2 first layouts, i've no idea what's going on and this is probably not the good way to do it.
What's the best solution here? Here is the xml code :
<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:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="800dp"
android:background="#353535"
tools:context=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/buttonStopAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/red_perso"
android:text="Stop tout"
android:textColor="#000000" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="200dp">
<ImageView
android:id="#+id/idTheoGonfle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/theosouffle" />
<ImageView
android:id="#+id/idChuteCJ"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/cjchute" />
<TextView
android:id="#+id/textTheoGonfle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="150dp"
android:background="#FFEB3B"
android:fontFamily="sans-serif-black"
android:gravity="center"
android:text="Théo gonfle"
android:textAllCaps="false"
android:textColor="#000000"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/idTheoGonfle" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="150dp"
android:background="#FFEB3B"
android:fontFamily="sans-serif-black"
android:text="TextView"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/idChuteCJ" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout4"
android:layout_width="match_parent"
android:layout_height="200dp">
<ImageView
android:id="#+id/imageView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_launcher_foreground" />
<ImageView
android:id="#+id/imageView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_launcher_foreground" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout3"
android:layout_width="match_parent"
android:layout_height="200dp">
<ImageView
android:id="#+id/imageView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="#tools:sample/avatars" />
<ImageView
android:id="#+id/imageView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="#tools:sample/avatars" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout2"
android:layout_width="match_parent"
android:layout_height="200dp">
<ImageView
android:id="#+id/imageView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="#tools:sample/avatars" />
<ImageView
android:id="#+id/imageView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="#tools:sample/avatars" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>```
look like you are begginer.
<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:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="800dp"
android:background="#353535"
tools:context=".MainActivity">
look like your problem
android:layout_height="800dp"
You set the fix height. Change it to match_parent.
<androidx.constraintlayout.widget.ConstraintLayout. And change root layout to FrameLayout or remove it.

Static buttons over top a scroll view android studio

I want to create an activity where i have 2 buttons at the bottom of the screen, and a scroll view above them. Inside of the scroll view i want a drop down menu where the user can select a series of exercises. How do I put the scroll view above the buttons and have them stay in the same spot when scrolling?
Code for 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:id="#+id/ConstraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".WorkoutsCreater">
<TextView
android:id="#+id/NameWorkoutTextView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:gravity="center"
android:text="Name of Workout:"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textSize="15dp"
app:layout_constraintBottom_toBottomOf="#+id/NameWorkoutInput"
app:layout_constraintEnd_toStartOf="#+id/NameWorkoutInput"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/NameWorkoutInput" />
<TextView
android:id="#+id/nameExercise1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:gravity="center"
android:text="Exercise 1:"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textSize="15dp"
app:layout_constraintBottom_toBottomOf="#id/spinnerExercise1"
app:layout_constraintEnd_toStartOf="#+id/NameWorkoutInput"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/spinnerExercise1" />
<EditText
android:id="#+id/NameWorkoutInput"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="40dp"
android:layout_marginRight="40dp"
android:inputType="text"
android:maxLength="20"
android:textSize="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/NameWorkoutTextView"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/BtnNew"
android:layout_width="77dp"
android:layout_height="77dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/circle_plus"
android:clickable="true"
android:focusable="true"
android:foreground="#drawable/ic_add_white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="#drawable/ic_add_white" />
<Button
android:id="#+id/BtnSave"
android:layout_width="77dp"
android:layout_height="77dp"
android:layout_marginStart="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/rounded_corners"
android:foreground="#drawable/ic_save_white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Spinner
android:id="#+id/spinnerExercise1"
android:layout_width="175dp"
android:layout_height="43dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/NameWorkoutInput" />
Image of activity
If you want to add a scrollview that stays above the two buttons, you can add a NestedScrollview inside the constraintlayout
<?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:id="#+id/ConstraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".WorkoutsCreater">
<androidx.core.widget.NestedScrollView
android:layout_width="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="#id/BtnNew"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/NameWorkoutTextView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:gravity="center"
android:text="Name of Workout:"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textSize="15dp"
app:layout_constraintBottom_toBottomOf="#+id/NameWorkoutInput"
app:layout_constraintEnd_toStartOf="#+id/NameWorkoutInput"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/NameWorkoutInput" />
<TextView
android:id="#+id/nameExercise1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:gravity="center"
android:text="Exercise 1:"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textSize="15dp"
app:layout_constraintBottom_toBottomOf="#id/spinnerExercise1"
app:layout_constraintEnd_toStartOf="#+id/NameWorkoutInput"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/spinnerExercise1" />
<EditText
android:id="#+id/NameWorkoutInput"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="40dp"
android:layout_marginRight="40dp"
android:inputType="text"
android:maxLength="20"
android:textSize="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/NameWorkoutTextView"
app:layout_constraintTop_toTopOf="parent" />
<Spinner
android:id="#+id/spinnerExercise1"
android:layout_width="175dp"
android:layout_height="43dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/NameWorkoutInput" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
<Button
android:id="#+id/BtnNew"
android:layout_width="77dp"
android:layout_height="77dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/ic_add_circle"
android:clickable="true"
android:focusable="true"
android:foreground="#drawable/ic_add_white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="#drawable/ic_add_white" />
<Button
android:id="#+id/BtnSave"
android:layout_width="77dp"
android:layout_height="77dp"
android:layout_marginStart="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/ic_remove_red_ba0a00"
android:foreground="#drawable/ic_save_white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Disclaimer: Nested layouts are more costlier than flat layouts
Please have a look at this https://developer.android.com/topic/performance/rendering/optimizing-view-hierarchies

How to load RecyclerView items step by step in NestedScrollView?

I have gallery page in my project. There are RecyclerView, ScrollView and other basic views in gallery page. My RecyclerView loads all images when open the page. This causes the app to freeze. I want to use RecyclerView feature like load items part by part.
Actually my XML is too long so I didn't add some views in following code.
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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:id="#+id/detail_fragment_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:clipChildren="false"
android:clipToPadding="false"
android:fillViewport="true"
android:fitsSystemWindows="false"
android:focusable="true"
tools:context=".DetailActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/detail_fragment_constraint"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:focusable="true"
android:scrollbars="none">
<TextView
android:id="#+id/feed_detail_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="12dp"
android:layout_marginTop="12dp"
android:paddingLeft="8dp"
android:paddingTop="2dp"
android:paddingRight="8dp"
android:paddingBottom="2dp"
android:textColor="#android:color/black"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/feed_detail_image" />
<TextView
android:id="#+id/feed_detail_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintBottom_toBottomOf="#+id/feed_detail_category"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/feed_detail_category" />
<TextView
android:id="#+id/feed_detail_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:paddingLeft="8dp"
android:paddingTop="8dp"
android:paddingRight="8dp"
android:paddingBottom="8dp"
android:textColor="#android:color/black"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/feed_detail_category" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/comment_recycler_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/no_comment_text" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

Error in using Recycler View and Scroll View together?

I have been facing issue using Recycler View and Scroll View together in the same bottom navigation activity in different tabs. I am hiding one of the view by using Visibility Gone in the java file.
I tried many solutions but nothing worked till now so I am posting here if someone can help me figure it out.
<android.support.constraint.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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.cartoonswikipedia.www.familyconnect.Main2Activity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="60dp"
android:layout_marginBottom="60dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/postrecycler"
android:layout_width="368dp"
android:layout_height="312dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp" />
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/colorPrimaryDark">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/toolbar_subtitle"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_gravity="left"
android:paddingLeft="10dp"
android:text="#string/app_name"
android:textColor="#FFFFFF"
android:textSize="30dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/profileimagee45"
android:layout_width="69dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="right"
android:clickable="true"
android:onClick="hi"
android:padding="12dp"
app:srcCompat="#drawable/c" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollview"
android:layout_marginTop="60dp"
android:layout_marginBottom="60dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<TableLayout
android:id="#+id/abc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<TextView
android:id="#+id/editemail"
android:layout_width="262dp"
android:layout_height="37dp"
android:textAppearance="#style/TextAppearance.AppCompat.Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.113" />
<ImageView
android:id="#+id/profileimage"
android:layout_width="87dp"
android:layout_height="88dp"
android:adjustViewBounds="false"
android:cropToPadding="false"
android:onClick="proimg"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.167"
android:clickable="false"/>
<EditText
android:id="#+id/editname"
android:layout_width="262dp"
android:layout_height="50dp"
android:ems="10"
android:hint="Name"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.338" />
<LinearLayout
android:id="#+id/abcdef"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/children"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Children"
android:textSize="25dp"/>
<ImageView
android:id="#+id/adddd"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</LinearLayout>
<EditText
android:id="#+id/editheight"
android:layout_width="262dp"
android:layout_height="50dp"
android:ems="10"
android:hint="Height in CM"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.338" />
<EditText
android:id="#+id/editweight"
android:layout_width="262dp"
android:layout_height="50dp"
android:ems="10"
android:hint="Weight in KG"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.338" />
<RelativeLayout>
<TextView
android:id="#+id/blood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp"
android:text="Blood Group"
android:textSize="25dp" />
</RelativeLayout>
<RelativeLayout>
<TextView
android:id="#+id/religion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp"
android:text="Religion"
android:textSize="25dp" />
</RelativeLayout>
<Button
android:id="#+id/editprofile"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:background="#000000"
android:onClick="edit"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Save Profile"
android:textColor="#ffffff" />
<Button
android:id="#+id/logout"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:background="#000000"
android:onClick="logout"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Log Out"
android:textColor="#ffffff"
android:textSize="15dp"
android:textStyle="bold"/>
</TableLayout>
</ScrollView>
<ProgressBar
android:id="#+id/empty_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.473"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.464" />
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_marginTop="60dp"
android:layout_marginBottom="60dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:theme="#style/AppTheme"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/navigation" />

Categories

Resources