特定の制約レイアウトにプログラムでImageButtonを追加したいと思います。具体的なガイドラインにも制約があります。これまでのところ私は以下のメソッドを実装していますが、debugText以外のエラーは発生しませんが、何も起こりません。ImageButtonをプログラムで作成する場合、ビューには追加されません。
public void addButtonImage() {
setContentView(R.layout.activity_homepage); // - Moved out of method
ConstraintLayout conL = (ConstraintLayout)findViewById(R.id.newLayout);
ImageButton previewImg = new ImageButton(this);
Guideline leftGl = (Guideline)findViewById(R.id.leftGideLine);
Guideline rightGL = (Guideline)findViewById(R.id.rightGuideLine);
ImageView header = (ImageView) findViewById(R.id.Header);
previewImg.setImageBitmap(displayImage); // displayImage variable assigned out of method
previewImg.setBackgroundColor(Color.parseColor("#FFFF00"));
conL.addView(previewImg);
ConstraintSet conS = new ConstraintSet();
conS.clone(conL);
conS.constrainHeight(pp.getId(), 90);
conS.constrainWidth(pp.getId(), 0);
conS.connect(previewImg.getId(), ConstraintSet.TOP, header.getId(), ConstraintSet.BOTTOM);
conS.connect(previewImg.getId(), ConstraintSet.LEFT, leftGl.getId(), ConstraintSet.RIGHT);
conS.connect(previewImg.getId(), ConstraintSet.RIGHT, rightGL.getId(), ConstraintSet.LEFT);
conS.applyTo(conL);
}
アドバイスをいただければ幸いです。
しかし、情報をありがとう、イメージや背景色はまだ表示されません。 –
訂正!何かが現れています!それは適切な場所ではなく、以下のalexscmarの答えと組み合わせる必要がありましたが、私と一緒に働くには十分です。どうもありがとう! –