10

I have a NestedScrollView in MotionLayout once Motion Scene is ended then NestedScrollView is visible but when i try scrolling the view no event's are going to NestedScrollView.

Video of Requirement

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

Motion Scene 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>

How can i use NestedScrollView inside MotionLayout?

Related thread's:

SOF question

Issue in google's motion layout demo application

UPDATE #1:

  • When i have static content i.e hard coded string in the ScrollView(some large string) then the scrolling is working but if i add a dynamic content i.e dynamic response string from an api then scrolling doesn't work.

  • Maybe Motion Layout is not re-calculating the dynamic change in the ScrollView not sure.

Anmol
  • 5,619
  • 3
  • 28
  • 54

0 Answers0