Android 如何让NestedScrollView在MotionLayout中滚动?
我在MotionLayout中有一个NestedScrollView一旦运动场景结束,NestedScrollView就可见了,但是当我尝试滚动视图时,没有任何事件会进入NestedScrollView 布局xml:Android 如何让NestedScrollView在MotionLayout中滚动?,android,android-nestedscrollview,android-motionlayout,Android,Android Nestedscrollview,Android Motionlayout,我在MotionLayout中有一个NestedScrollView一旦运动场景结束,NestedScrollView就可见了,但是当我尝试滚动视图时,没有任何事件会进入NestedScrollView 布局xml: 更新#1: 当我在ScrollView中有静态内容,即硬编码字符串(一些大字符串)时,滚动正在工作,但如果我添加了动态内容,即api中的动态响应字符串,则滚动不工作 也许运动布局没有在ScrollView中重新计算动态变化不确定 您找到了动态内容的解决方案吗?找到了解决方
更新#1:
- 当我在ScrollView中有静态内容,即硬编码字符串(一些大字符串)时,滚动正在工作,但如果我添加了动态内容,即api中的动态响应字符串,则滚动不工作
- 也许运动布局没有在ScrollView中重新计算动态变化不确定
您找到了动态内容的解决方案吗?找到了解决方案吗?
<?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 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>