I'm having a problem to programmatically add views to a ConstraintLayout
, and set up all the constraints required for the layout to work.
What I have at the moment doesn't work:
ConstraintLayout layout = (ConstraintLayout) findViewById(R.id.mainConstraint);
ConstraintSet set = new ConstraintSet();
set.clone(layout);
ImageView view = new ImageView(this);
layout.addView(view,0);
set.connect(view.getId(), ConstraintSet.TOP, layout.getId(), ConstraintSet.TOP, 60);
set.applyTo(layout);
The ImageView
doesn't even appear on the layout. When adding to a RelativeLayout
, it works like a charm.
What can I do to create the constraints I need, so that my layout work again?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…