MyWay
MyWay

Reputation: 1025

listview - set negative margin for item of listview programmatically

I have a problem with making negative margin for view of item which belongs to listview.

My items look like this:

enter image description here

I would like to lift second item and third and so on. The final effect should look like this

enter image description here

I tried with setTop method.

 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 is my custom class which inheriting from ImageView

Height of this triangle is knew after I first draw it on layout, but it's not a problem. I try to play with LayoutParameters, but it's also doesn't work for my.

Is there any posibility to make whole item margin negative?

I saw question, which talk about setting margin for item in linearlayout or relative layout or inside the item of listview, but I can't find nothing aboout changing margin of whole item.

Upvotes: 1

Views: 693

Answers (1)

Yaw Asare
Yaw Asare

Reputation: 548

In your xml file, in your listview set the divider height to a negative number to get an overlaping effect.

like this

android:dividerHeight="-10.0dp"

Upvotes: 1

Related Questions