cardslib icon indicating copy to clipboard operation
cardslib copied to clipboard

Shadow with CardViewNative

Open warmax opened this issue 10 years ago • 7 comments

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!

warmax avatar Nov 09 '14 15:11 warmax

Can I ask you to try the same code with a card standalone? (not in grid)

gabrielemariotti avatar Nov 12 '14 07:11 gabrielemariotti

Just checked and there is no shadow either.

I also tested with an empty card in a CardViewNative... I'm using the emulator btw.

warmax avatar Nov 12 '14 22:11 warmax

I am going to investigate about it.

gabrielemariotti avatar Nov 14 '14 08:11 gabrielemariotti

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}.

warmax avatar Nov 16 '14 02:11 warmax

Voting for this. Shadow is not shown in android 5.0+

deinlandel avatar Sep 15 '15 09:09 deinlandel

Addition: I am using StaggeredGridView. Can it be the source of a problem?

deinlandel avatar Sep 15 '15 09:09 deinlandel

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.

deinlandel avatar Sep 16 '15 05:09 deinlandel