как сделать прокручиваемый макет ограничения

#android #android-layout #scrollview #android-constraintlayout

#Android #android-макет #scrollview #android-constraintlayout

Вопрос:

Привет, я пытаюсь сделать прокручиваемым один из макетов моего фрагмента, но не могу достичь своей цели, несмотря на то, что искал решение в течение многих часов. Я удалил все layout_constraintBottom_toBottomOf="parent" ограничения внутри основного макета ограничений, а также установил высоту макета wrap_content . Наконец, я установил fillViewPort для атрибута ScrollView значение true, но результат остается прежним. Может кто-нибудь мне помочь, пожалуйста? Вот мой файл .xml :

 <?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:fillViewport="true">
        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@ id/layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

                <ProgressBar
                    android:id="@ id/challengeProgressBar"
                    style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Large"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_marginTop="300dp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <ImageView
                    android:id="@ id/errorImageView"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_marginTop="300dp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <androidx.constraintlayout.widget.ConstraintLayout
                    android:id="@ id/visibleLayout"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent">

                        <TextView
                            android:id="@ id/profileNameTextView"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="10dp"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toBottomOf="@ id/profileImageView" />

                        <ImageView
                            android:id="@ id/profileImageView"
                            android:layout_width="150dp"
                            android:layout_height="150dp"
                            android:layout_marginStart="143dp"
                            android:layout_marginTop="45dp"
                            android:layout_marginEnd="143dp"
                            android:padding="5dp"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="parent"
                            tools:src="@tools:sample/avatars" />

                        <TextView
                            android:id="@ id/uploadStatusTextView"
                            android:layout_width="wrap_content"
                            android:layout_height="0dp"
                            android:layout_marginTop="4dp"
                            android:layout_marginBottom="4dp"
                            app:layout_constraintBottom_toTopOf="@ id/profileImageView"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="parent" />

                        <TextView
                            android:id="@ id/nbPointsTextView"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="30dp"
                            android:textAppearance="@style/TextAppearance.AppCompat.Display1"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintHorizontal_bias="0.498"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toBottomOf="@ id/profileNameTextView" />

                        <Button
                            android:id="@ id/completedChallengesButton"
                            android:layout_width="0dp"
                            android:layout_height="40dp"
                            android:layout_marginStart="75dp"
                            android:layout_marginTop="52dp"
                            android:layout_marginEnd="75dp"
                            android:text="@string/completed_challenges"
                            android:textSize="10sp"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintHorizontal_bias="0.0"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toBottomOf="@ id/nbPointsTextView" />

                        <androidx.recyclerview.widget.RecyclerView
                            android:id="@ id/completedChallengesRecyclerView"
                            android:layout_width="0dp"
                            android:layout_height="150dp"
                            android:layout_marginStart="75dp"
                            android:layout_marginEnd="75dp"
                            android:background="@drawable/border"
                            android:visibility="visible"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintHorizontal_bias="0.0"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toBottomOf="@ id/completedChallengesButton" />

                        <Button
                            android:id="@ id/challengesButton"
                            android:layout_width="0dp"
                            android:layout_height="40dp"
                            android:layout_marginStart="75dp"
                            android:layout_marginEnd="75dp"
                            android:text="@string/current_challenges"
                            android:textSize="10sp"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toBottomOf="@ id/completedChallengesRecyclerView" />

                        <androidx.recyclerview.widget.RecyclerView
                            android:id="@ id/challengesRecyclerView"
                            android:layout_width="0dp"
                            android:layout_height="150dp"
                            android:layout_marginStart="75dp"
                            android:layout_marginTop="8dp"
                            android:layout_marginEnd="75dp"
                            android:background="@drawable/border"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintHorizontal_bias="1.0"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toBottomOf="@ id/challengesButton" />

                </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
 

Комментарии:

1. Не могли бы вы попробовать добавить android:nestedScrollingEnabled=»false» в оба ваших RecyclerView ?.

2. проблема остается той же :/

Ответ №1:

Причина заключается в использовании scrollable view ( RecyclerView ) внутри ScrollView , поэтому вы должны поместить это в свой RecyclerView

 android:nestedScrollingEnabled="false"
 

Но лучшее решение — превратить весь экран только в один RecyclerView

Комментарии:

1. проблема остается той же :/

2. обновите высоту и ширину вашего RecyclerView, как показано ниже android:layout_width="match_parent" android:layout_height="wrap_content"