My xml is composed by one constraint layout. Inside this there are 2 buttons and 1 nested scroll view. Inside the ScrollView
there are various elements including recycle view. I would like that the recycle view not scroll but scroll only the nested scroll view. I have disabled the scroll of recycle view in this mode
(recyclerView.setNestedScrollingEnabled(false);
)
but the problem is that the nested scroll view not scrolling. Can you help me?
I attach the code below.
The code start in this mode :
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/azzera"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_marginStart="40dp"
android:layout_marginBottom="28dp"
android:background="@drawable/rounded_4lati"
android:backgroundTint="@color/azzurro"
android:elevation="@dimen/dimen8"
android:paddingTop="@dimen/dimen8"
android:text="@string/azzera"
android:textAlignment="center"
android:textColor="#FFFFFF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/conferma"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="28dp"
android:background="@drawable/rounded_4lati"
android:backgroundTint="@color/azzurro"
android:paddingTop="@dimen/dimen8"
android:text="@string/conferma"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:elevation="@dimen/dimen8"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<android.support.v4.widget.NestedScrollView 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"
android:fillViewport="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="@+id/view1"
android:layout_width="0dp"
android:layout_height="48dp"
android:background="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/view2"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:background="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/view1" />
<View
android:id="@+id/view3"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:background="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/view2" />
<TextView
android:id="@+id/mostraPreferiti"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="@string/mostraPreferiti"
android:textColor="@color/black"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/view3" />
<TextView
android:id="@+id/creditiEcm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:text="@string/creditiECM"
android:textColor="@color/black"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/view1" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:inputType="number"
android:hint="@string/zero"
android:text="@string/editText"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="@+id/creditiEcm"
app:layout_constraintTop_toTopOf="@+id/view1"
android:autofillHints="" />
<Button
android:id="@+id/buttonMeno"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginTop="6dp"
android:layout_marginEnd="16dp"
android:background="@drawable/ic_remove_circle_azzurro_24dp"
android:gravity="center"
android:textAlignment="gravity"
android:textColor="@color/azzurro"
android:textSize="24sp"
app:layout_constraintEnd_toStartOf="@+id/buttonPiu"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/buttonPiu"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginTop="6dp"
android:layout_marginEnd="32dp"
android:background="@drawable/ic_add_circle_azzurro_24dp"
android:gravity="center"
android:textAlignment="gravity"
android:textColor="@color/azzurro"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/mostraCorsiPassati"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="@string/mostraCorsiPassati"
android:textColor="@color/black"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/view2"
app:layout_constraintTop_toTopOf="@+id/view2" />
<Switch
android:id="@+id/switch_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="32dp"
android:theme="@style/SwitchTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/view2" />
<Switch
android:id="@+id/switch_button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="32dp"
android:theme="@style/SwitchTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/view3" />
<android.support.v7.widget.AppCompatTextView
android:id="@+id/professioni"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="90dp"
android:layout_marginEnd="8dp"
android:text="@string/professione2"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold"
app:fontFamily="@font/sanfrancisco"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mostraCorsiPassati" />
<SearchView
android:id="@+id/searchBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:background="#fff"
android:elevation="2dp"
app:layout_constraintHorizontal_bias="0.557"
app:layout_constraintLeft_toRightOf="parent"
app:layout_constraintRight_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/professioni"
app:queryHint="Cerca..">
</SearchView>
<android.support.v7.widget.RecyclerView
android:id="@+id/listProfessioni"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/searchBar"
android:orientation="vertical"
>
</android.support.v7.widget.RecyclerView>
<TextView
android:id="@+id/professioniNonDisponibili"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:text="@string/professioniNonDisponibili"
android:textAlignment="center"
android:textColor="@color/gray"
android:textSize="18sp"
app:autoSizeMaxTextSize="@dimen/dimen20"
app:autoSizeMinTextSize="@dimen/dimen12"
app:autoSizeTextType="uniform"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/error" />
<ImageView
android:id="@+id/error"
android:layout_width="@dimen/dimen80"
android:layout_height="@dimen/dimen80"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/ic_error_outline_gray_24dp"
android:contentDescription="@string/TODO"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/searchBar"
app:layout_constraintVertical_bias="0.105" />
<ProgressBar
android:id="@+id/progress"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:alpha="1"
android:minWidth="80dp"
android:minHeight="80dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/searchBar"
app:layout_constraintVertical_bias="0.168" />
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
NestedScrollView is just like ScrollView , but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.
A ConstraintLayout is a ViewGroup which allows you to position and size widgets in a flexible way. Note: ConstraintLayout is available as a support library that you can use on Android systems starting with API level 9 (Gingerbread).
As i answered in comments
For Someone other facing same problem. This might help.
For some reasons ScrollView
doesn't scroll when having ConstraintLayout
inside it.
For Workaround we can use LinearLayout
or RelativeLayout
instead of ConstraintLayout inside ScrollView
. OR
As OP does put the ConstraintLayout
inside Linear or Relative Layout
does the trick.
According to Ali Ahmed's answer, a ScrollView
doesn't scroll if you have a ConstraintLayout
inside it. Well that's not true. I have been using ConstraintLayout
inside ScrollView
and everything works perfectly fine. Well the problem with the code that you posted is that you are using 0dp
as the layout_height
of your RecyclerView
. 0dp
means match_parent
. You should be using wrap_content
as your layout_height
. So that the RecyclerView
expands its height according to the elements in it. Doing so will make your code work fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With