Home > Enterprise >  ScrollView is not providing scrolling feature
ScrollView is not providing scrolling feature

Time:09-30

The ScrollView is not scrolling. Although I have it and it is set to wrap_content, it contains only one child element, but there is not scrolling feature at all.How can I make it scroll? The scrolling should start after EditText that's why I have it below EditText, not as parent. Thanks in advance

<?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"
    android:fitsSystemWindows="true">

<androidx.appcompat.widget.AppCompatImageView
    android:id="@ id/message"
    android:layout_width="20dp"
    android:layout_height="20dp"
    android:layout_marginTop="20dp"
    android:layout_marginEnd="@dimen/dp_20"
    android:src="@drawable/ic_messages"
    app:layout_constraintBottom_toBottomOf="@ id/textViewDrawable"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<androidx.appcompat.widget.AppCompatTextView
    android:id="@ id/main_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="@dimen/dp_16"
    android:layout_marginTop="@dimen/dp_10"
    android:fontFamily="@font/manrope_normal"
    android:text="Платежи"
    android:textColor="#071222"
    android:textSize="34sp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/message" />

<androidx.appcompat.widget.AppCompatEditText
    android:id="@ id/search_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginHorizontal="@dimen/dp_16"
    android:layout_marginTop="@dimen/dp_10"
    android:background="@drawable/search_bar"
    android:drawableStart="@drawable/ic_search_grey"
    android:drawablePadding="@dimen/dp_10"
    android:hint="Какой платеж ищете?"
    android:paddingVertical="@dimen/dp_8"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/main_title" />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/search_bar">

    <androidx.appcompat.widget.LinearLayoutCompat
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">


        <androidx.cardview.widget.CardView
            android:id="@ id/card_popular"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginHorizontal="@dimen/dp_16"
            android:layout_marginTop="@dimen/dp_26"
            app:cardCornerRadius="@dimen/dp_12"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/search_bar">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@ id/payments_list"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/dp_16"
                android:layout_marginTop="20dp"
                android:layout_marginRight="@dimen/dp_16"
                android:layout_marginBottom="@dimen/dp_20"
                app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
                app:spanCount="4"
                tools:listitem="@layout/recycler_popular_payment" />

        </androidx.cardview.widget.CardView>

        <androidx.appcompat.widget.LinearLayoutCompat
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/dp_16"
            android:background="@color/colorWhite"
            android:orientation="vertical"
            android:paddingHorizontal="@dimen/dp_16"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/card_popular">

            <androidx.appcompat.widget.AppCompatTextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/dp_16"
                android:text="Сохраненные" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@ id/saved_list"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                tools:listitem="@layout/recycler_item_saved_payment" />

        </androidx.appcompat.widget.LinearLayoutCompat>
    </androidx.appcompat.widget.LinearLayoutCompat>
</ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>

CodePudding user response:

Your ScrollView should have these properties:

android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"

Using those and some dummy TextView(s) inside the LinearLayout I see that scrolling is working.

CodePudding user response:

Now update the scroll view

    <ScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    android:fillViewport="true"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/search_bar">
  • Related