List view with custom view items with partially overlaps (Android)

android, android-layout, android-listview

Solution

I managed to achieve this by using scroll view with a single relative layout as a child. I then dynamically place the views by defining a rule and margin:

for (int i = 0; i < 30; i++) {
        TextView tv = new TextView(context);
        tv.setText("Text \n Text" + i);

        tv.setBackgroundColor(i % 2 == 0 ? Color.RED : Color.GREEN);

        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        lp.leftMargin = 0;
        lp.topMargin = (i * 45);
        rl.addView(tv, lp);
}

Later, you can control the positioning of the sub-views by changing their y value (for example: if you want to add animation).

This is the final result:

Problem

I want to implement a list in Android that contains some customized views. My problem is that I want the the views will be put one after the other with a little overlap between them. like in the following schema: I also want to control this overlap in such a way that when the user clicks on one of the items, they will move apart from each other. I tried to extend ListView but it seems to be very obscured, any suggestions? Edit: This can be more clear: I did it by setting the divider height to -50dp. this is exactly what I want to achieve, but somehow it doesn't reflect on my app.

Original source