View list with custom view elements with partially overlapping (Android)

I want to implement a list on Android that contains some custom views. My problem is that I want the views to be placed one after the other with a little coincidence between them. as in the following diagram: enter image description here

I also want to control this overlap in such a way that when the user clicks on one of the elements, they will move from each other.

I tried to extend the ListView, but it seems very obscure, any suggestions?

Edit: This may be more clear:

enter image description here

I did this by setting the height of the separator to -50dp. this is exactly what I want to achieve, but for some reason it does not affect my application.

+4
source share
2 answers

I managed to achieve this using a scroll view with one relative arrangement as a child. Then I dynamically place the views, defining the 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 subrecords by changing their y value (for example: if you want to add animation).

This is the end result:

Layout containing overlapping items

+3
source

This can probably be achieved using the Camera.setTranslate function. See Android: Vertical ListView with overlapping rows and Android: vertical 3d list for similar questions (with solutions)

+1
source

All Articles