views-widgets-samples
views-widgets-samples copied to clipboard
Shadow rendering issue if CardView added in programmatically created ViewGroup
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
setMargin for the cardview (8dp) should fix the problem
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.