0

I'd like to do something like this in a recycle view, but I don't know how to proceed.

RecyclerView with "inner" elevation

In this recyclerview, there are 2 items (but can be more, it's dynamic), with no space between them, and elevation on the common background.

I tried to set a white background color and elevation on my recycler view, but to see the elevation I'm forced to put margins, which I don't want to. Padding don't solve this either.

I tried to add elevation on the children too, but I dont want space between them (as in the picture above)

It is the first time I'm having trouble with RecyclerView, so I don't even know where I can find an answer. Help me please !

DanielBarbarian
  • 5,093
  • 12
  • 35
  • 44
Tanguy C
  • 183
  • 1
  • 6

1 Answers1

0

This component is called CardView and here you have some tutorials how to use it:

https://developer.android.com/training/material/lists-cards.html

https://code.tutsplus.com/tutorials/getting-started-with-recyclerview-and-cardview-on-android--cms-23465

How to accomplish what you showed on image depends on how many cards you want to have and how many sub-items can be in each card. For example to have what's on the image you don't need RecyclerView, just one card with LinearLayout into which you can inflate several subviews.

Rafal Zawadzki
  • 963
  • 6
  • 15
  • Hello Rafal, thanks for answering ! Actually, that's not exaclty what I'm looking for... With CardView, my item would be separated, and I don't want this. I'm looking for something a bit like this http://codetheory.in/wp-content/uploads/2015/01/Screenshot_2015-01-29-11-29-21.png but with padding left and right, with only one "section" – Tanguy C Nov 16 '16 at 16:42
  • I already tried to use a linear layout like this, myLinearLayout.addView(View.inflate(this, R.layout.planning_view, null)), but I can have more than 100 items, so it's not really efficient, and it can freeze the UI thread – Tanguy C Nov 16 '16 at 16:52
  • Try using a RecyclerView inside a CardView. The elevation will be handled by the CardView. – AlphaQ Nov 16 '16 at 17:03
  • I understand now. I think this will help you: http://stackoverflow.com/questions/27475178/how-do-i-make-wrap-content-work-on-a-recyclerview or http://stackoverflow.com/questions/32337403/making-recyclerview-fixed-height-and-scrollable Basically, you need RecyclerView that wraps_content in CardView :) – Rafal Zawadzki Nov 16 '16 at 17:04