2016-12-27 72 views
2

我有一个ConstraintLayout内部的视图(Linearlayout)具有以下属性:删除/编辑ConstraintLayout内部视图的约束编程

android:id="@+id/myView" 
app:layout_constraintTop_toBottomOf="@+id/anotherView" 
app:layout_constraintLeft_toLeftOf="parent" 
app:layout_constraintRight_toRightOf="parent" 

在一些场合,我要对齐myView到左侧,由只是删除正确的约束。但是我无法这样做。
我试着用下面简单地复制和应用的约束参数:

ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(holder.myView.getLayoutParams()); 
holder.myView.setLayoutParams(layoutParams); 

layoutParams始终接收设置空参数,并将着眼于左上角。也许是因为我在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); 
} 

回答

4

有一个错误(将被固定在下一版本)设置布局PARAMS你做到这一点的时候。在此期间,您可以这样做:

ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) holder.myView.getLayoutParams(); 
layoutParams.rightToRight = ConstraintLayout.LayoutParams.UNSET; 
holder.myView.setLayoutParams(layoutParams);