Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the app:layout_constraintHorizontal_bias="" in the ConstraintLayout

In my XML-File I have a ConstaintLayout. There I have a ImageView with this settings:

<ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="1"
            app:layout_constraintStart_toEndOf="@+id/game_square"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@mipmap/ic_game_quadrat"
            android:visibility="invisible"
            android:id="@+id/game_right"/>

How can I access in the java file on the app:layout_constraintHorizontal_bias="1" to change it to for example 0.

Moritz

like image 910
Moritz Avatar asked Dec 01 '22 11:12

Moritz


1 Answers

You can try something like

ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(context, R.id.activity_constraint);
float biasedValue = 0f;
constraintSet.setHorizontalBias(R.id.game_right, biasedValue);
constraintSet.applyTo((ConstraintLayout) findViewById(R.id.activity_constraint));
like image 162
Yuliwee Avatar answered Dec 04 '22 12:12

Yuliwee