小编meb*_*s08的帖子

我如何以编程方式更改约束

我需要一些ConstraintLayout的帮助.

我有3个垂直对齐的按钮.Button1和Button3可见,Button2不可见.当我单击Button1时,Button2应该是可见的.

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:onClick="on_expand"
    android:text="Button"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_marginTop="8dp"
    android:text="Button"
    android:visibility="invisible"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/button1" />

<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:text="Button"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@id/button1" />
Run Code Online (Sandbox Code Playgroud)

我怎么设置

app:layout_constraintTop_toBottomOf="@id/button2"
Run Code Online (Sandbox Code Playgroud)

在Button3上

我找到了这个

Button b1 = (Button)findViewById(R.id.button1);
Button b2 = (Button) findViewById(R.id.button2);
Button b3 = (Button) findViewById(R.id.button3);    

ConstraintSet constraintSet = new ConstraintSet();
        constraintSet.connect("What must i set here????");
        constraintSet.clone(mConstraintLayout);
        constraintSet.applyTo(mConstraintLayout);
Run Code Online (Sandbox Code Playgroud)

android android-layout android-constraintlayout

3
推荐指数
1
解决办法
3317
查看次数