#android #android-constraintlayout #android-motionlayout
#Android #android-constraintlayout #android-motionlayout
Вопрос:
Итак, мы пытаемся имитировать поведение peek-able BottomSheetLayout
(вид снизу, выглядывающий из нижней части экрана, который отображается в полноэкранном режиме при прокрутке вверх, примерно так: https://www.youtube.com/watch?v=yrZVLL-z6P4 ) использование MotionLayout
, версия 2.0.0-alpha4
.
Проблема в том, что OnSwipe
переход в режиме просмотра не применяется к самому представлению, он, по-видимому, применяется ко всему представлению внизу, в данном случае a RecyclerView
. Поэтому, когда мы прокручиваем RecyclerView
, выполняется переход.
root_view.xml
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.motion.widget.MotionLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/motion_scene">
<androidx.recyclerview.widget.RecyclerView
android:id="@ id/recyclerview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:clipToPadding="false"
android:paddingBottom="@dimen/margin_48"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@ id/btn"
android:layout_width="match_parent"
android:layout_height="@dimen/size_48"
android:elevation="@dimen/elevation_12"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@ id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="@dimen/elevation_12"
android:rotation="90"
app:layout_constraintBottom_toBottomOf="@id/btn"
app:layout_constraintEnd_toEndOf="@id/btn"
app:layout_constraintTop_toTopOf="@id/btn" />
<FrameLayout
android:id="@ id/fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="@dimen/elevation_8"
app:layout_constraintTop_toBottomOf="parent" />
</androidx.constraintlayout.motion.widget.MotionLayout>
</FrameLayout>
motion_scene.xml
<Transition
android:id="@ id/swipe"
app:constraintSetEnd="@id/end"
app:constraintSetStart="@id/start"
app:duration="250">
<OnSwipe
app:dragDirection="dragUp"
app:touchAnchorId="@id/btn" />
</Transition>
<ConstraintSet android:id="@ id/start">
<Constraint
android:id="@id/fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="parent" />
<Constraint
android:id="@id/btn"
android:layout_width="match_parent"
android:layout_height="@dimen/size_48"
app:layout_constraintBottom_toBottomOf="parent" />
</ConstraintSet>
<ConstraintSet android:id="@ id/end">
<Constraint
android:id="@id/fragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn" />
<Constraint
android:id="@id/btn"
android:layout_width="match_parent"
android:layout_height="@dimen/size_48"
app:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
Комментарии:
1. О, видимо, это сделано специально… Подробнее на issuetracker.google.com/issues/130471393
2. Они добавили touchRegionId в alpha-05
Ответ №1:
мне помогло использование обоих app:touchAnchorId
и app:touchRegionId
вместе.
<OnSwipe
app:dragDirection="dragUp"
app:touchAnchorId="@id/btn"
app:touchRegionId="@id/btn"/>
Комментарии:
1. большое спасибо, что указали app: touchRegionId, в противном случае движение перетаскивания применяется ко всему экрану
Ответ №2:
Вы должны отключить вложенную прокрутку, чтобы остановить анимацию, запускаемую Recyclerview. Выполните следующие действия, и все будет в порядке 🙂
<androidx.recyclerview.widget.RecyclerView
android:id="@ id/recyclerview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:clipToPadding="false"
android:paddingBottom="@dimen/margin_48"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:nestedScrollingEnabled="false" />