【发布时间】:2021-12-19 02:56:03
【问题描述】:
我正在尝试从 this tutorial 实现此动画,但本教程与回收器视图的不同之处在于我想通过底部表单实现它
这是我正在做的事情的布局
<?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/activity_main_scene"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageViewAvatar"
android:layout_width="140dp"
android:layout_height="140dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:src="@drawable/ic_baseline_add_reaction_24"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_editor_absoluteX="0dp">
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/bottomSheet"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_alignParentBottom="true"
android:background="@drawable/bottom_view_bg"
android:orientation="vertical"
app:behavior_hideable="false"
app:behavior_peekHeight="90dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<View
android:layout_width="80dp"
android:layout_height="2dp"
android:layout_gravity="center"
android:layout_marginTop="16dp"
android:background="@color/white" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvHorzinatal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/item_rv" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:text="Swipe Up"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_rv" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.motion.widget.MotionLayout>
这是我的场景布局
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
motion:constraintSetEnd="@+id/end"
motion:constraintSetStart="@id/start"
motion:duration="1000">
<OnSwipe
app:dragDirection="dragUp"
app:touchAnchorId="@+id/bottomSheet"
app:touchAnchorSide="top" />
<KeyFrameSet />
</Transition>
<ConstraintSet android:id="@+id/start"></ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@id/imageViewAvatar"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</Constraint>
</ConstraintSet>
但是每当我将 Onswipe 放在坐标布局或其中的约束上时,它都不起作用我该如何解决这个问题?
【问题讨论】:
标签: android bottom-sheet android-motionlayout android-bottomsheetdialog