2016-12-27 73 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);