Adding constraints programmatically

后端 未结 1 1501
名媛妹妹
名媛妹妹 2021-02-19 20:11

What is the translation to java code of the following XML instructions used in a layout definition with a constraint layout?

app:layout_constraintBottom_toBottom         


        
1条回答
  •  伪装坚强ぢ
    2021-02-19 21:14

    Here is an example of adding constraints programatically,

    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); 
    

    To know more details you can refer Constraint layout

    0 讨论(0)
提交回复
热议问题