Ive got a view like below :
 <org.rayanmehr.atlas.shared.customview.CustomTextView     android:id="@+id/tvDownVoteCount"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginLeft="6dp"     app:layout_constraintVertical_bias="0"     app:layout_constraintTop_toBottomOf="@+id/anchorHelper"     app:layout_constraintLeft_toRightOf="@+id/tvDownVoteIcon"     app:layout_constraintBottom_toBottomOf="@+id/imgComment"     />   how can i modify the value of app:layout_constraintVertical_bias or any other constraint property programmatically without having top set the whole set of the properties again in my activity ?
Open the layout file (activity_main. xml) in Android Studio and click the Design tab at the bottom of the editor window. In the Component Tree window, right-click LinearLayout and then choose Convert layout to ConstraintLayout from the context menu.
WRAP_CONTENT); ConstraintLayout. MarginLayoutParams layoutParams = new ConstraintLayout. MarginLayoutParams(newLayoutParams); layoutParams. setMargins(0, 0, 0, 0); toolbar.
Here is what I did (no need for ConstraintSet, we can work directly on the constraints themselves):
ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) myView.getLayoutParams(); params.horizontalBias = 0.2f; // here is one modification for example. modify anything else you want :) myView.setLayoutParams(params); // request the view to use the new modified params   it worked like a charm when I had a SeekBar and a TextView below it (aligned to it both left+right), and I wanted to update the TextView position to be under the SeekBar's cursor, so I had to update the horizontal bias params on the SeekBar's OnSeekBarChangeListener
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With