I've been trying to overlap two adjacent positions in a recyclerview, but fail to do so. I would like a part of the first position overlap/draw over the second position.
I've have been playing around with a custom RecyclerView.ItemDecoration and it's getItemOffsets, however that just seem to be able to add padding/margin on a position, not translating it to a new position outside it's viewparent.
Anyone got any pointers of how to achieve this with a recyclerview?
Well, you can also add negative margin in a 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));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With