here is my layout :
...
<android.support.constraint.ConstraintLayout
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.6"
>
<android.support.constraint.ConstraintLayout
android:id="@+id/myclayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.2"
app:layout_constraintTop_toTopOf="parent"
></android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
...
how to set constraintHeight_percent programmatically ?
I tried with ConstraintSet but did not work
ConstraintSet set = new ConstraintSet();
set.constrainPercentHeight(R.id.myclayout, (float) 0.4);
set.applyTo(((ConstraintLayout) vw.findViewById(R.id.myclayout)));
There are two types of guidelines: Now we can position guidelines in three different ways: By using (layout_constraintGuide_begin) to specify a fixed distance from the left or the top of a layout. By using (layout_constraintGuide_end) to specify a fixed distance from the right or the bottom of a layout.
Open your layout in Android Studio and click the Design tab at the bottom of the editor window. In the Component Tree window, right-click the layout and click Convert layout to ConstraintLayout.
Used to create a horizontal create guidelines. This view is invisible, but it still takes up space for layout purposes.
constrainedWidth. Specify if the horizontal dimension is constrained in case both left & right constraints are set and the widget dimension is not a fixed dimension.
the right answer is :
ConstraintLayout mConstrainLayout = (ConstraintLayout) vw.findViewById(R.id.myclayout); ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) mConstrainLayout.getLayoutParams(); lp.matchConstraintPercentHeight = (float) 0.4; mConstrainLayout.setLayoutParams(lp);
I went with using a ConstraintSet to update the width and height of a ConstraintLayout's child:
val set = ConstraintSet()
set.clone(parentLayout) // parentLayout is a ConstraintLayout
set.constrainPercentWidth(childElement.id, .5f)
set.constrainPercentHeight(childElement.id, .5f)
set.applyTo(parentLayout)
...the float values should be a percentage mapped to the unit interval.
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