以编程方式删除/编辑ConstraintLayout内部的视图约束

bbe*_*nis 2 android android-constraintlayout

Linearlayout在内有一个ConstraintLayout具有以下属性的视图():

 android:id="@+id/myView"
 app:layout_constraintTop_toBottomOf="@+id/anotherView"
 app:layout_constraintLeft_toLeftOf="parent"
 app:layout_constraintRight_toRightOf="parent"
Run Code Online (Sandbox Code Playgroud)

在某些情况下,我希望myView通过简单地删除右侧约束来向左对齐。但是我不能这样做。
我尝试使用以下内容,简单地复制并应用约束参数:

 ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(holder.myView.getLayoutParams());
 holder.myView.setLayoutParams(layoutParams);
Run Code Online (Sandbox Code Playgroud)

但是layoutParams总是收到一个空的参数集,并将视图发送到左上角。也许是因为我在a内使用了它recyclerView

它在内部的外观如何recyclerView

public void onBindViewHolder(final RecyclerView.ViewHolder basicHolder, int position) {
ProfileAdapter.UserInfoViewHolder holder = (ProfileAdapter.UserInfoViewHolder) basicHolder;
ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(holder.myView.getLayoutParams(??));
holder.myView.setLayoutParams(layoutParams); 
}
Run Code Online (Sandbox Code Playgroud)

Nic*_*ard 5

以您的方式设置布局参数时,存在一个错误(将在下一版本中修复)。同时,您可以执行以下操作:

ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) holder.myView.getLayoutParams();
layoutParams.rightToRight = ConstraintLayout.LayoutParams.UNSET;
holder.myView.setLayoutParams(layoutParams);
Run Code Online (Sandbox Code Playgroud)