在Android应用程序中,我试图以编程方式将自定义ConstraintLayout视图添加到垂直方向LinearLayout.
我设置LayoutParams到MATCH_PARENT宽度和WRAP_CONTENT在身高ConstraintLayout秒.但是,当我运行应用程序时,ConstraintView所有应用程序都被刷新,内容重叠.以下是一些相关的片段和我的应用程序的屏幕截图.我该如何纠正这个问题?
public class ItemView extends ConstraintLayout {
LinearLayout linearButtons;
LinearLayout linearText;
public ItemView(Context context, String name, String price, ArrayList<String> guests,
ArrayList<String> checked, int id) {
...
addView(linearText);
addView(linearButtons);
set.clone(this);
set.connect(linearText.getId(), ConstraintSet.LEFT, this.getId(),
ConstraintSet.LEFT, 8);
set.connect(linearText.getId(), ConstraintSet.TOP, this.getId(),
ConstraintSet.TOP, 8);
set.connect(linearButtons.getId(), ConstraintSet.RIGHT, this.getId(),
ConstraintSet.RIGHT, 8);
set.connect(linearButtons.getId(), ConstraintSet.TOP, this.getId(),
ConstraintSet.TOP, 8);
}
Run Code Online (Sandbox Code Playgroud)
别处:
for (Item it:r.getItems()) {
ItemView itemView = new ItemView(this, it.getName(), nf.format(it.getPrice()), dinerlist, it.getGuests(), i); …Run Code Online (Sandbox Code Playgroud)