如何以编程方式修改约束布局? [英] how to MODIFY a constraint layout programmatically?
本文介绍了如何以编程方式修改约束布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的视图如下:
<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"
/>
我如何通过编程方式修改app:layout_constraintVertical_bias
或任何其他约束属性的值,而又没有在我的活动中再次重新设置整个属性集?
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 ?
推荐答案
我刚刚在此处,您可以使用ConstraintSet
来实现此目标,如下所示:
I just found the answer in here and you can use ConstraintSet
to achieve this like below:
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(context, R.id.activity_constraint);
//for example lets change the vertical bias of tvDownVoteIcon
float biasedValue = 0.2f;
constraintSet.setVerticalBias(R.id.tvDownVoteIcon, biasedValue);
//you can do any other modification and then apply
constraintSet.applyTo( (ConstraintLayout) findViewById(R.id.activity_constraint));
这篇关于如何以编程方式修改约束布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文