I want to make "slide in" animation to my view in Constraint Layout with Constraint Set and Transition Manager. For this I need to position my view below the parent view. So it will slide out from screen and slide back ti the screen. Is it possible in Constraint Layout?
In code I need my index_navigation
position below the parent view.
<TextView
android:id="@+id/page_number"
style="@style/RoundBackgroundStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="@drawable/page_number_round_bg"
android:textColor="#fff"
android:visibility="visible"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<me.example.ui.extensions.PageNavigator
android:id="@+id/index_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/index_scroll_background"
android:clickable="true"
android:focusable="true"
app:layout_constraintBottom_toBottomOf="parent"
>
<TextView
android:id="@+id/index_navigation_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:textColor="@color/colorPrimaryLight"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
/>
</me.example.ui.extensions.PageNavigator>
Animation code
val constraintSet1 = ConstraintSet()
constraintSet1.clone(rootView)
val constraintSet2 = ConstraintSet()
constraintSet2.clone(this, R.layout.activity_main)
constraintSet2.setTranslationY(R.id.index_navigation, 150f)
viewModel.shouldShowIndexPagerLiveEvent.observe(this, Observer { shouldShow ->
shouldShow?.let {
TransitionManager.beginDelayedTransition(rootView)
val constraint = if (it) constraintSet1 else constraintSet2
constraint.applyTo(rootView)
}
})
Have you tried to set the position of index_navigation? Something like this.
index_navigation_view.setY(parent_view_height)
I see that you have found an answer, but figured I would bring up another possibility that exists, which is to use MotionLayout (which is an extension of ConstraintLayout), available for API 18 and up.
Here is a link to the developer tutorial.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.