Android MotionLayout中的多个过渡问题 [英] Problem with multiple Transitions in Android MotionLayout

查看:78
本文介绍了Android MotionLayout中的多个过渡问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩Android中的MotionLayout.我正在使用Alpha 2版本.

I'm playing around with the MotionLayout in Android. I'm using the alpha 2 version.

'com.android.support.constraint:constraint-layout:2.0.0-alpha2'

我想对两个不同的按钮单击做出反应,并为每个按钮触发一个动画.我目前的方法是在 MotionScene 中设置两个 Transitions ,并在每个触发器中分别设置一个 OnClick 触发器.

I want to react to two different button clicks and trigger an animation for each of them. My current approach is to set two Transitions in the MotionScene with an OnClick trigger in each one.

问题在于似乎只找到第一个过渡.对于第二个,什么也没有发生.我是在做错什么,还是可以只为每个 MotionScene 设置一个过渡?如果是这样,是否有其他解决方案?

The problem is that only the first transition seems to be found. For the second one just nothing happens. Am I doing something wrong or can you just set one transition per MotionScene? If that's the case ist there a different solution to the problem?

这是我的运动场景的重要部分

Here are the important parts of my Motion Scene

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

<Transition
    motion:constraintSetStart="@id/startHome"
    motion:constraintSetEnd="@id/endHome"
    motion:duration="300">
    <OnClick
        motion:mode="toggle"
        motion:target="@+id/imageView_bottom_home" />
</Transition>

<Transition
    motion:constraintSetStart="@id/startSearch"
    motion:constraintSetEnd="@id/endSearch"
    motion:duration="300">
    <OnClick
        motion:mode="toggle"
        motion:target="@+id/imageView_bottom_search" />
</Transition>

<ConstraintSet android:id="@+id/startSearch">
    <Constraint
        android:id="@id/imageView_bottom_search"
        ...startConstraints... />
</ConstraintSet>

<ConstraintSet android:id="@+id/endSearch">
    <Constraint
        android:id="@id/imageView_bottom_search"
        ...endConstraints... />
</ConstraintSet>

<ConstraintSet android:id="@+id/startHome">
    <Constraint
        android:id="@id/imageView_bottom_home"
        ...startConstraints... />
</ConstraintSet>

<ConstraintSet android:id="@+id/endHome">
    <Constraint
        android:id="@id/imageView_bottom_home"
        ...endConstraints... />
</ConstraintSet>

任何帮助表示赞赏.

最诚挚的问候

推荐答案

我遇到了同样的问题.我发现的解决方案是选择哪个过渡:

I had the same problem. The solution I found was to select which one transitions:

(在Java代码中)...

(in java code)...

MotionLayout motionConteiner = findViewById(R.id.motion_container);
button1.setOnClickListener((v) -> {
            motionConteiner.setTransition(R.id.start1, R.id.end1);
            motionConteiner.transitionToEnd();//                
        });
button2.setOnClickListener((v) -> {
            motionConteiner.setTransition(R.id.start2, R.id.end2);
            motionConteiner.transitionToEnd();//                
        });

这篇关于Android MotionLayout中的多个过渡问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆