2017-09-25 134 views
2

什麼是在具有約束佈局的佈局定義中使用的以下XML指令的Java代碼的翻譯?以編程方式添加約束

app:layout_constraintBottom_toBottomOf="@+id/Button1" 
app:layout_constraintTop_toTopOf="@+id/Button1" 
app:layout_constraintLeft_toLeftOf="@+id/Button2" 
app:layout_constraintRight_toRightOf="Button2" 
+1

檢查了這一點http://www.techotopia.com/index.php/Managing_Constraints_using_ConstraintSet – Kuls

+0

謝謝,它運作良好,也許你想用一個簡短的例子從該頁面做出簡短的回答,以便我可以接受它 – codeKiller

回答

2

這是編程添加約束的一個例子,

ConstraintLayout mConstraintLayout = (ConstraintLayout)fndViewById(R.id.mainConstraint); 
ConstraintSet set = new ConstraintSet(); 

ImageView view = new ImageView(this); 
mConstraintLayout.addView(view,0); 
set.clone(mConstraintLayout); 
set.connect(view.getId(), ConstraintSet.TOP, mConstraintLayout.getId(), ConstraintSet.TOP, 60); 
set.applyTo(mConstraintLayout); 

要知道更多的細節,你可以參考Constraint layout

+0

謝謝,我會接受答案,當它允許我這樣做時 – codeKiller

+0

不客氣(y) – Kuls

相關問題