views-widgets-samples icon indicating copy to clipboard operation
views-widgets-samples copied to clipboard

Shadow rendering issue if CardView added in programmatically created ViewGroup

Open wingoku opened this issue 9 years ago • 2 comments

I have found a weird issue in CardView. When I try to add a programmatically created CardView to an xml inflated View, shadow is rendered on Lollipop devices. However if I add this cardView inside a programmatically created ViewGroup Eg. RelativeLayout, & then add this relativeLayout in xml inflated Viewgroup the shadow isn't rendered on lollipop. I don't know if I have to set a property that OS sets automatically while inflating xml views & that is mandatory to set if we are creating ViewGroups programmatically in order to draw shadows. Please note that on pre lollipop devices shadows are rendered no matter in which ViewGroup do I add the cardView. How can I resolve this issue?

Code Here: https://gist.github.com/wingoku/eee1e95bea313f8a0206

wingoku avatar Apr 25 '15 13:04 wingoku

setMargin for the cardview (8dp) should fix the problem

roibareket avatar Nov 01 '15 11:11 roibareket

I had a similar issue and this helped me: http://stackoverflow.com/questions/25632756/cardview-has-lost-margin-when-inflating

I was passing null as the CardView's parent to View.inflate(), which meant that the xml layout_marginLeft etc parameters were being ignored.

luoapril avatar Feb 26 '16 20:02 luoapril