listview - 以编程方式为 listview 的项目设置负边距

listview - set negative margin for item of listview programmatically

我在为属于列表视图的项目的视图设置负边距时遇到问题。

我的物品是这样的:

我想举第二个和第三个等等。最终效果应该是这样的

我试过 setTop 方法。

 private class MyCustomAdapter extends ArrayAdapter<Integer> {

        public MyCustomAdapter()
        {
            super(ListOfBeaconPlaces.this, R.layout.list_of_places_item_view, drawables);
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            View takenView = convertView;

            if (takenView == null)
            {
                takenView = getLayoutInflater().inflate(R.layout.list_of_places_item_view, null, false);
            }
            final CuttedImageView cuttedImage = (CuttedImageView) takenView.findViewById(R.id.list_item_view);
            cuttedImage.setImageResource(drawables.get(position));
            if (cuttedImage.getHeightOfDrawnTransparentTriangle() != 0)
            {
                cuttedImage.setTop( (int)-cuttedImage.getHeightOfDrawnTransparentTriangle());
            }

            return takenView;
        }
    }

CuttedImageView 是我的习惯 class 继承自 ImageView

这个三角形的高度是我第一次在layout上画出来的,但没问题。我尝试使用 LayoutParameters,但它也不适合我。

是否有可能使整个项目利润为负?

我看到了问题,其中讨论了在线性布局或相对布局中或在列表视图的项目内部为项目设置边距,但我找不到关于更改整个项目的边距的任何信息。

在您的 xml 文件中,在您的列表视图中将分隔线高度设置为负数以获得重叠效果。

像这样

android:dividerHeight="-10.0dp"