【发布时间】:2017-05-29 19:13:01
【问题描述】:
在一个 android 应用程序中,我试图以编程方式将自定义的 ConstraintLayout 视图添加到垂直方向的 LinearLayout。
我在ConstraintLayouts 中将LayoutParams 设置为MATCH_PARENT 的宽度和WRAP_CONTENT 的高度。但是,当我运行该应用程序时,ConstraintView 全部被卷曲并且内容重叠。下面是一些相关的 sn-ps 和我的应用程序的屏幕截图。我该如何解决这个问题?
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);
}
其他地方:
for (Item it:r.getItems()) {
ItemView itemView = new ItemView(this, it.getName(), nf.format(it.getPrice()), dinerlist, it.getGuests(), i);
ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT);
itemView.setLayoutParams(params);
vg.addV[enter image description here][1]iew(itemView);
Log.d("ItemView Children: ", itemView.getWidth()+" "+itemView.getHeight());
【问题讨论】:
标签: android android-layout android-constraintlayout