ConstraintLayoutの他のビューと同じ場所にビューを追加しようとしましたが、追加されたビューは他のビューのLayoutParamsを取得しません。
追加されたビューは、コンテナの左上に表示されます。
これは私のコードです:
TextView cloneView = new TextView(getContext());
cloneView.setLayoutParams(otherView.getLayoutParams());
mainContainer.addView(cloneView);
ConstraintLayoutにビューを追加するには、ConstraintSetを使用して制約を追加する必要があります。
View v = findViewById(...);
ConstraintLayout cl = (ConstraintLayout) findViewById(...);
ConstraintSet c = new ConstraintSet();
cl.addView(v);
int id = v.getId();
c.clone(cl);
c.connect(id, ConstraintSet.Top, otherViewIdAboveV, ConstraintSet.BOTTOM, 0);
...
other constraints
...
c.applyTo(cl);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加