首页 > 解决方案 > 为什么 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

        }
    }

边距图片

标签: javaandroidlayoutandroid-constraintlayoutbreadcrumbs

解决方案


推荐阅读