cardslib
cardslib copied to clipboard
Shadow with CardViewNative
I'm trying to set elevation to the cards inside a grid view with lolipop but i cannot get it to work.
This is the cardview:
<it.gmariotti.cardslib.library.view.CardViewNative xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card="http://schemas.android.com/apk/res-auto" android:id="@+id/list_cardId" android:layout_width="match_parent" android:layout_height="match_parent" card:card_layout_resourceID="@layout/card_top_stock" />
Then i set the elevation for the cards: card.setCardElevation(getResources().getDimension(R.dimen.card_elevation));
But no shadow is cast. I've also tried from xml with
card:cardElevation="6dp"
I'm not using a CardShadowView in my custom card. Any ideas what could cause this?
Thank and keep up the good work!
Can I ask you to try the same code with a card standalone? (not in grid)
Just checked and there is no shadow either.
I also tested with an empty card in a CardViewNative... I'm using the emulator btw.
I am going to investigate about it.
I see this warnings in logcat
11-16 03:03:59.406 29977-29977/com.apps.test W/CardView﹕ Shadow size is being clipped by the max shadow size. See {CardView#setMaxCardElevation}.
Voting for this. Shadow is not shown in android 5.0+
Addition: I am using StaggeredGridView. Can it be the source of a problem?
Ok, in case google leads someone here. Add the following to values-v21/styles.xml:
<style name="native_list_card">
<item name="android:layout_marginLeft">4dp</item>
<item name="android:layout_marginRight">4dp</item>
<item name="android:layout_marginBottom">6dp</item>
<item name="android:layout_marginTop">2dp</item>
</style>
You can change DP values to anything you want. Note that the greater the elevation, the more margins should be.