Reputation: 13
I have a custum view in the background and a motion layout on top of that. Here is my code
<?xml version="1.0" encoding="utf-8"?>
<layout 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"
tools:context=".ui.DetailFragment">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.example.complexmotion.customui.DownloadIcon
android:id="@+id/customIcon"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.motion.widget.MotionLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/fragment_detail_scene">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@drawable/background_card_white"
android:translationZ="5dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/guideline" />
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/_20dp"
android:elevation="@dimen/_20dp"
android:translationZ="7dp"
app:cardCornerRadius="10dp"
app:cardUseCompatPadding="true"
app:layout_constraintBottom_toBottomOf="@id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/guideline">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cl_for_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/fileName"
style="@style/textStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_20dp"
android:layout_marginTop="@dimen/_20dp"
android:fontFamily="@font/roboto"
android:text="@string/file_name"
android:textColor="@color/grey"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/downloadedFileName"
style="@style/textStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_20dp"
android:layout_marginTop="@dimen/_20dp"
android:text="@string/file_name"
android:textColor="@color/grey"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/fileName" />
<TextView
android:id="@+id/status"
style="@style/textStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/_20dp"
android:layout_marginStart="@dimen/_20dp"
android:text="@string/status"
android:textColor="@color/grey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/downloadedFileName" />
<TextView
android:id="@+id/downloadStatus"
style="@style/textStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="@color/tealBlue"
app:layout_constraintStart_toStartOf="@id/downloadedFileName"
app:layout_constraintTop_toTopOf="@id/status" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.motion.widget.MotionLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
I have a motion scene where I want to play a transtion only when my recycler view is swiped up or down. So my motion scene looks like this
<?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">
<ConstraintSet android:id="@+id/start"/>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/recyclerView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:translationZ="15dp"
android:layout_marginTop="100dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Constraint
android:id="@+id/cardView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_20dp"
android:layout_marginEnd="@dimen/_20dp"
android:layout_marginTop="-20dp"
android:translationZ="7dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/recyclerView" />
</ConstraintSet>
<Transition
app:constraintSetEnd="@id/end"
app:constraintSetStart="@+id/start"
app:duration="1000">
<OnSwipe app:touchAnchorId="@id/recyclerView" />
<KeyFrameSet>
<KeyPosition
app:framePosition="45"
app:keyPositionType="parentRelative"
app:motionTarget="@id/cardView"
app:percentY="0.1" />
</KeyFrameSet>
</Transition>
</MotionScene>
I also want user to interact with my custom view. But onSwipe restricts it from happening. If I remove onSwipe inside the transition then user can interact Screen shot of a user interacting with the background but my transition won't play smoothly. Complete project on git
I tried doing it setting progress of the motionlayout but it's not smooth, I also tried
limitBoundsTo
that also not working the way I desire.
Upvotes: 0
Views: 29