java - 为什么 leftMargin 将一半的数量添加到顶部和底部?
问题描述
我的布局似乎在其相邻边的顶部和底部添加了额外的 1/2 边距。这只是保证金的作用吗?有没有办法重新定义边距,使其只调整左侧或右侧?我也可能使用了错误的参数。
下面是错误的图片。
我想要整个图像周围的 vMargin。
public Part2View(Context context, List<ImageView> images, int vMargin) {
super(context);
ConstraintLayout container = new ConstraintLayout(context); // create the parent container for the images
addView(container); // add it to Part2View
container.setId(0); // set its ID to 0. This lets us refer to it later
for (int i = 0; i < images.size(); i++) {
ImageView img = images.get(i); // The image
//img.setId(i+1);
// TODO: Make sure the image scales properly
img.setAdjustViewBounds(true);
//other stuff
// TODO: Add the image to the interactor hierarchy
container.addView(img);
// TODO: Set the image ID so you can refer to it later
img.setId(i+1);
// TODO: Create some ConstraintLayout.LayoutParams and set them so the image will expand in X and minimize Y
ConstraintLayout.LayoutParams params;
params = new ConstraintLayout.LayoutParams(
ConstraintLayout.LayoutParams.MATCH_PARENT,
ConstraintLayout.LayoutParams.MATCH_PARENT);
params.leftToLeft = 0;
params.rightToRight = 0;
if(i == 0) {
params.topToTop = 0;
} else {
params.topToBottom = i;
}
params.rightMargin = vMargin;
if(i < images.size() - 1) {
//
// params.bottomMargin = vMargin;
}
img.setLayoutParams(params);
// TODO: Set the parameters to use the constraint layout so that the image looks like it did in Part1
}
}
解决方案
推荐阅读
- visual-studio - 在 Unity Il2Cpp 构建解决方案中添加编译符号
- python - python中的游戏。如何通过修改脚本来确保人们不作弊?
- javascript - 通过 Javascript 和 PHP 加载 HTML 是一种好习惯吗?
- c++ - 在构造函数中模拟函数调用
- scala - 如何更新火花数据框的单元格
- python - 如何获取类成员的类型注释?
- intellij-idea - 调试控制台在 IntelliJ 试用版中不起作用
- python - jaydebeapi executemany() 方法不能使用一个参数
- sql - 在 Laravel 查询中一起使用 find() 和 with()
- php - PHP PHAR 有多个点的文件名问题