【问题标题】:ScrollView is not providing scrolling featureScrollView 不提供滚动功能
【发布时间】:2021-09-29 16:50:11
【问题描述】:

ScrollView 没有滚动。虽然我有它并且它设置为wrap_content,它只包含一个子元素,但根本没有滚动功能。我怎样才能让它滚动?滚动应该在 EditText 之后开始,这就是为什么我将它放在 EditText 下面,而不是作为父级。提前致谢

<?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>

【问题讨论】:

    标签: android xml


    【解决方案1】:

    您的ScrollView 应具有以下属性:

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

    LinearLayout 中使用这些和一些虚拟的TextView(s) 我看到滚动正在工作。

    【讨论】:

      【解决方案2】:

      现在更新滚动视图

          <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">
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多