Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
223 views
in Technique[技术] by (71.8m points)

android - How to change transition values according to orientation in a MotionLayout?

I create a scene that resizes a view from full to half the screen. It works on portrait mode, but the layout_height value is not enough for landscape mode. Is there a way to set a different value of a property in a XML scene file according to a specific orientation? If not, do I have to change it programmatically and how?

<MotionScene 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">

<Transition
    motion:constraintSetEnd="@+id/end"
    motion:constraintSetStart="@id/start"
    motion:duration="500">
   <KeyFrameSet>
   </KeyFrameSet>
</Transition>

<ConstraintSet android:id="@+id/start">
    <Constraint
        android:id="@+id/content_parent"
        motion:layout_constraintEnd_toEndOf="parent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        motion:layout_constraintTop_toTopOf="parent"
        motion:layout_constraintStart_toStartOf="parent" />
</ConstraintSet>

<ConstraintSet android:id="@+id/end">
    <Constraint
        android:id="@+id/content_parent"
        motion:layout_constraintEnd_toEndOf="parent"
        android:layout_width="match_parent"
        android:layout_height="@dimen/section_height"
        motion:layout_constraintTop_toTopOf="parent"
        motion:layout_constraintStart_toStartOf="parent" />

</ConstraintSet>

UPDATE @ivan-wooll Here's how I did:

//dimens.xml
<dimen name="section_height" tools:ignore="ResourceCycle">@dimen/section_height</dimen>

//dimens.xml(port)
<dimen name="section_height">280dp</dimen>

//dimens.xml(land)
<dimen name="section_height">60dp</dimen>
question from:https://stackoverflow.com/questions/65937806/how-to-change-transition-values-according-to-orientation-in-a-motionlayout

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I finally solved my problem with XML (@ivan-wooll suggestion, thumbs up) and Kotlin code (mine)

override fun onConfigurationChanged(newConfig: Configuration) {
    super.onConfigurationChanged(newConfig)
    val csEnd = binding.motionLayoutVideo.getConstraintSet(R.id.end)
    var consHeight= resources.getDimensionPixelSize(R.dimen.section_height)
    csEnd.apply {
       constrainHeight(R.id.content_parent, consHeight)
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...