Android 以编程方式进行运动布局

Android 以编程方式进行运动布局,android,android-motionlayout,Android,Android Motionlayout,这是我在这个平台上的第一个问题,我正在制作一个应用程序的一部分,其中我需要使用运动布局动态移动文本视图,但是当我添加我的showBubble()方法时,当执行该应用程序时不显示文本视图,我错过了什么? 我认为在检测BubbleUi的id时,XML中存在一些错误,但归根结底,这可能比看起来更容易,您知道:( 注:我正在翻译这篇文章,如果在写作中有任何错误,很抱歉 XML: 当我添加motionBubble.loadlayoutDescription(R.xml.scene_气泡)时,文本视图不可见

这是我在这个平台上的第一个问题,我正在制作一个应用程序的一部分,其中我需要使用运动布局动态移动文本视图,但是当我添加我的
showBubble()
方法时,当执行该应用程序时不显示文本视图,我错过了什么? 我认为在检测BubbleUi的id时,XML中存在一些错误,但归根结底,这可能比看起来更容易,您知道:(

注:我正在翻译这篇文章,如果在写作中有任何错误,很抱歉

XML:


当我添加motionBubble.loadlayoutDescription(R.xml.scene_气泡)时,文本视图不可见,如果我删除相同的文本视图,则文本视图会显示,但不会设置动画当我添加motionBubble.loadlayoutDescription(R.xml.scene_气泡)时,文本视图不可见,如果我删除相同的文本视图,则文本视图会显示,但不会设置动画
<?xml version="1.0" encoding="utf-8"?>
<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="3500"
        >
        <OnClick
            motion:targetId="@+id/Bubble"
            motion:clickAction="toggle"
            />

    </Transition>


    <ConstraintSet android:id="@+id/start">

    <Constraint
        android:id="@id/Bubble"

        android:layout_width="70dp"
        android:layout_height="70dp"

        motion:layout_constraintTop_toTopOf="parent"
        motion:layout_constraintStart_toStartOf="parent"
        motion:layout_constraintEnd_toEndOf="parent"

        >
        <CustomAttribute
            motion:attributeName="backgroundColor"
            motion:customColorValue="@color/colorGreenLight"
            />

    </Constraint>


    </ConstraintSet>

    <ConstraintSet android:id="@+id/end">

        <Constraint
            android:id="@+id/Bubble"
            android:layout_width="100dp"
            android:layout_height="100dp"

            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintStart_toStartOf="parent"
            motion:layout_constraintEnd_toEndOf="parent"
            >
            <CustomAttribute
                motion:attributeName="backgroundColor"
                motion:customColorValue="@color/colorGreenLight"
                />

        </Constraint>


    </ConstraintSet>

</MotionScene>
private void ShowBubble(String tempWord) {
        //Create Motion layout.
        MotionLayout motionBubble = new MotionLayout(ActivityGame.this);
        motionBubble.setId(View.generateViewId());
        motionBubble.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
        LinearLayout.LayoutParams linearParams= new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
        linearParams.setMargins(5,0,5,0);
        motionBubble.setLayoutParams(linearParams);

        //Create the Bubble.
        TextView BubbleUi = new TextView(ActivityGame.this);
        BubbleUi.setId(R.id.Bubble);

        BubbleUi.setText(tempWord);
        BubbleUi.setTextSize(24);
        BubbleUi.setTextColor(getResources().getColor(R.color.colorDefaultWhite));
        BubbleUi.setBackgroundColor(getResources().getColor(R.color.colorGreenLight));
        BubbleUi.setLayoutParams(new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.WRAP_CONTENT, ConstraintLayout.LayoutParams.WRAP_CONTENT));

        BubbleUi.setGravity(Gravity.CENTER);

        motionBubble.addView(BubbleUi,0);

        ConstraintSet constraintSetBubble = new ConstraintSet();
        constraintSetBubble.clone(motionBubble);

        constraintSetBubble.connect(BubbleUi.getId(),ConstraintSet.TOP,ConstraintSet.PARENT_ID,ConstraintSet.TOP);
        constraintSetBubble.connect(BubbleUi.getId(),ConstraintSet.START,ConstraintSet.PARENT_ID,ConstraintSet.START);
        constraintSetBubble.connect(BubbleUi.getId(),ConstraintSet.END,ConstraintSet.PARENT_ID,ConstraintSet.END);

        constraintSetBubble.applyTo(motionBubble);

        //set transition.

        motionBubble.loadLayoutDescription(R.xml.scene_bubbles);
        linearLayoutBubbles.addView(motionBubble,indiceBubble);

        CurrentMotionBubbleCycle [indiceBubble] = motionBubble;

        motionBubble.transitionToStart();
        motionBubble.transitionToEnd();
    }