title: motion layout programmatically
body: <p>This is my first question on this platform, I am making a part of an app where I need to dynamically move text views with motion layout, but when I add my <code>showBubble ()</code> method this when executing the app does not show the text view, there is something I miss?
  I think there is some error in the XML when detecting the id of the BubbleUi, but at the end of the day, it may be easier than it seems, you know :(</p>
  <p>note: I am translating this text, sorry if there is any mistake in the writing</p>
  <p>XML:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;MotionScene xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:motion=&quot;http://schemas.android.com/apk/res-auto&quot;&gt;
  
      &lt;Transition
          motion:constraintSetEnd=&quot;@id/end&quot;
          motion:constraintSetStart=&quot;@+id/start&quot;
  
          motion:duration=&quot;3500&quot;
          &gt;
          &lt;OnClick
              motion:targetId=&quot;@+id/Bubble&quot;
              motion:clickAction=&quot;toggle&quot;
              /&gt;
  
      &lt;/Transition&gt;
  
  
      &lt;ConstraintSet android:id=&quot;@+id/start&quot;&gt;
  
      &lt;Constraint
          android:id=&quot;@id/Bubble&quot;
  
          android:layout_width=&quot;70dp&quot;
          android:layout_height=&quot;70dp&quot;
  
          motion:layout_constraintTop_toTopOf=&quot;parent&quot;
          motion:layout_constraintStart_toStartOf=&quot;parent&quot;
          motion:layout_constraintEnd_toEndOf=&quot;parent&quot;
  
          &gt;
          &lt;CustomAttribute
              motion:attributeName=&quot;backgroundColor&quot;
              motion:customColorValue=&quot;@color/colorGreenLight&quot;
              /&gt;
  
      &lt;/Constraint&gt;
  
  
      &lt;/ConstraintSet&gt;
  
      &lt;ConstraintSet android:id=&quot;@+id/end&quot;&gt;
  
          &lt;Constraint
              android:id=&quot;@+id/Bubble&quot;
              android:layout_width=&quot;100dp&quot;
              android:layout_height=&quot;100dp&quot;
  
              motion:layout_constraintBottom_toBottomOf=&quot;parent&quot;
              motion:layout_constraintStart_toStartOf=&quot;parent&quot;
              motion:layout_constraintEnd_toEndOf=&quot;parent&quot;
              &gt;
              &lt;CustomAttribute
                  motion:attributeName=&quot;backgroundColor&quot;
                  motion:customColorValue=&quot;@color/colorGreenLight&quot;
                  /&gt;
  
          &lt;/Constraint&gt;
  
  
      &lt;/ConstraintSet&gt;
  
  &lt;/MotionScene&gt;
  </code></pre>
  <p>java:</p>
  <pre><code>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();
      }
  </code></pre>