Overlapping positions / views in recycliewiew

I am trying to overlap two adjacent positions in recyclerview, but cannot do this. I would like part of the first position to overlap / draw the second position.

I played with a custom RecyclerView.ItemDecoration and its getItemOffsets, however, it looks like it can add padding / margin to a position rather than moving it to a new position outside of its viewparent.

Does anyone have pointers on how to achieve this with recyclerview?

+3
source share
1 answer

Well, you can also add a negative margin to RecyclerView.ItemDecoration .


Example:

ItemDecorator.java

public class ItemDecorator extends RecyclerView.ItemDecoration { private final int mSpace; public ItemDecorator(int space) { this.mSpace = space; } @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { outRect.left = mSpace; outRect.right = mSpace; outRect.bottom = mSpace; outRect.top = mSpace; } } 

MainActivity.java

 public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ArrayList<String> arrayList = new ArrayList<>(); arrayList.add("Hi"); arrayList.add("World"); arrayList.add("What"); RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rec1); //Negative margin! ItemDecorator itemDecorator = new ItemDecorator(-30); recyclerView.setAdapter(new CustomAdapter(arrayList)); recyclerView.addItemDecoration(itemDecorator); recyclerView.setLayoutManager(new LinearLayoutManager(this)); } } 
+7
source

All Articles