【发布时间】:2023-03-25 15:47:02
【问题描述】:
我尝试以编程方式添加 ConstraintLayout。它正在工作,但 WRAP_CONTENT 不工作。布局始终为MATCH_PARENT。
Android 开发者页面没有为 ConstraintLayout.LayoutParams 列出 WRAP_CONTENT
我的代码:
RelativeLayout rl_main = findViewById(R.id.rl_main);
ConstraintLayout cl = new ConstraintLayout(this);
cl.setId(0);
ConstraintLayout.LayoutParams clp = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.WRAP_CONTENT, ConstraintLayout.LayoutParams.MATCH_CONSTRAINT_WRAP);
cl.setLayoutParams(clp);
cl.setBackgroundColor(Color.parseColor("#000000"));
rl_main.addView(cl);
【问题讨论】:
标签: android android-layout layout android-constraintlayout layoutparams