Как разрешить NestedScrollView прокручивать в MotionLayout?

У меня есть NestedScrollView в MotionLayout, когда сцена движения заканчивается, тогда NestedScrollView становится видимым, но когда я пытаюсь прокрутить представление, никакие события не идут в NestedScrollView.

Видео с требованиями

Макет xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout 
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"
app:layoutDescription="@xml/motion_scene"
tools:context=".screens.moviedetail.controller.MovieDetailFragment">

<ImageView
    android:id="@+id/movieDetailPosterImageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/poster_image"
    android:scaleType="centerCrop"
    android:src="@drawable/ic_image_24px" />

<TextView
    android:id="@+id/movieDetailMovieTitleTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/movieTitleBackground"
    android:fontFamily="sans-serif-smallcaps"
    android:gravity="center_vertical"
    android:padding="@dimen/commonPadding"
    android:text="@string/movie_title"
    android:textColor="@android:color/white"
    android:textSize="@dimen/commonTextSize" />

<androidx.core.widget.NestedScrollView
    android:id="@+id/detailScrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <TextView
            android:id="@+id/movieDetailMovieOverviewHeadTextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="@string/movie_detail_heading_font"
            android:gravity="center_vertical"
            android:paddingStart="@dimen/commonPadding"
            android:paddingLeft="@dimen/commonPadding"
            android:paddingTop="@dimen/commonPadding"
            android:paddingEnd="@dimen/commonPadding"
            android:paddingRight="@dimen/commonPadding"
            android:text="@string/overview"
            android:textColor="@color/headTextColor"
            android:textSize="@dimen/commonTextSize" />

        <TextView
            android:id="@+id/movieDetailMovieOverviewTextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:fontFamily="@string/movie_detail_heading_font"
            android:gravity="center_vertical"
            android:maxLines="@integer/overviewMaxLength"
            android:paddingStart="@dimen/commonPadding"
            android:paddingLeft="@dimen/commonPadding"
            android:paddingEnd="@dimen/commonPadding"
            android:paddingRight="@dimen/commonPadding"
            android:paddingBottom="@dimen/commonPadding"
            android:textColor="@color/textColor"
            android:textSize="@dimen/commonTextSize" />

        <TextView
            android:id="@+id/movieDetailMovieRatingTextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="@string/movie_detail_heading_font"
            android:gravity="center_vertical"
            android:padding="@dimen/commonPadding"
            android:text="@string/movie_rating"
            android:textColor="@color/headTextColor"
            android:textSize="@dimen/commonTextSize" />

        <TextView
            android:id="@+id/movieDetailMovieReleaseDataTextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="@string/movie_detail_heading_font"
            android:gravity="center_vertical"
            android:padding="@dimen/commonPadding"
            android:text="@string/release_data"
            android:textColor="@color/headTextColor"
            android:textSize="@dimen/commonTextSize" />

    </androidx.appcompat.widget.LinearLayoutCompat>
</androidx.core.widget.NestedScrollView>

Сцена движения xml

<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<ConstraintSet android:id="@+id/start">
    <Constraint
        android:id="@id/movieDetailPosterImageView"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_marginEnd="0dp"
        motion:layout_constraintEnd_toEndOf="parent"
        motion:layout_constraintStart_toStartOf="parent"
        motion:layout_constraintTop_toTopOf="parent"
        motion:layout_editor_absoluteX="0dp"
        motion:layout_editor_absoluteY="0dp" />
    <Constraint
        android:id="@id/movieDetailMovieTitleTextView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:alpha="0"
        motion:layout_constraintEnd_toEndOf="parent"
        motion:layout_constraintStart_toStartOf="parent"
        motion:layout_constraintTop_toBottomOf="@id/movieDetailPosterImageView" />

    <Constraint
        android:id="@id/detailScrollView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:alpha="0"
        motion:layout_constraintEnd_toEndOf="parent"
        motion:layout_constraintStart_toStartOf="parent"
        motion:layout_constraintTop_toBottomOf="@id/movieDetailMovieTitleTextView" />
</ConstraintSet>

<ConstraintSet android:id="@+id/end">
    <Constraint
        android:id="@id/movieDetailPosterImageView"
        android:layout_width="0dp"
        android:layout_height="250dp"
        android:layout_marginTop="0dp"
        android:layout_marginBottom="-1dp"
        motion:layout_constraintEnd_toEndOf="parent"
        motion:layout_constraintStart_toStartOf="parent"
        motion:layout_constraintTop_toTopOf="parent" />
    <Constraint
        android:id="@id/movieDetailMovieTitleTextView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:alpha="1"
        motion:layout_constraintBottom_toBottomOf="parent"
        motion:layout_constraintEnd_toEndOf="parent"
        motion:layout_constraintStart_toStartOf="parent"
        motion:layout_constraintTop_toBottomOf="@id/movieDetailPosterImageView"
        motion:layout_constraintVertical_bias="0" />

    <Constraint
        android:id="@id/detailScrollView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:alpha="1"
        motion:layout_constraintEnd_toEndOf="parent"
        motion:layout_constraintStart_toStartOf="parent"
        motion:layout_constraintTop_toBottomOf="@id/movieDetailMovieTitleTextView" />
</ConstraintSet>

<Transition
    motion:constraintSetEnd="@id/end"
    motion:constraintSetStart="@id/start"
    motion:duration="500"
    motion:motionInterpolator="bounce">

    <OnSwipe
        motion:dragDirection="dragUp"
        motion:touchAnchorId="@id/movieDetailPosterImageView"
        motion:touchAnchorSide="bottom" />

</Transition>

Как я могу использовать NestedScrollView внутри MotionLayout?

Связанные темы:

вопрос SOF

Проблема с демонстрационным приложением Google Motion Layout

ОБНОВЛЕНИЕ №1:

  • Когда у меня есть статический контент, то есть жестко закодированная строка в ScrollView (некоторая большая строка), прокрутка работает, но если я добавляю динамический контент, то есть строку динамического ответа из api, прокрутка не работает.

  • Возможно, Motion Layout не пересчитывает динамическое изменение в ScrollView, не уверен.


person Anmol    schedule 15.02.2020    source источник
comment
вы нашли решение проблемы с динамическим контентом?   -  person Boe-Dev    schedule 20.06.2020
comment
нашли какое-нибудь решение?   -  person Jashan PJ    schedule 22.10.2020


Ответы (1)


Добавлять

android:descendantFocusability="blocksDescendants"

К LinearLayout внутри NestedScrollView

person Mohhamed Nabil    schedule 26.07.2021