Cardview lost its "elevation" after I started using it in Ragments, how to solve?

Asked

Viewed 116 times

1

Using in activities the elevation works normally, after I put in Fragments, it became "flat".

  • I don’t know if it makes much sense, but it might be a bug from CardView. The xml you put is the same in both?

  • yes, it’s identical, there’s nothing different, until I tried to change the properties to see if it solves but it didn’t solve.

  • He even tried the property cardElevation? You could put the XML from Fragment and of Activity of it as a whole?

  • I already used cardElevation and did not help. I did not understand this second part

  • You have to see how is calling type, android:cardElevation app:cardElevarion cardview:cardElevation

  • well, it still didn’t help. I didn’t understand what you said about putting the XML of Fragment and Activity as a whole

  • 2

    I say that it would be good to put the XML of the layout of Activity and Fragment, just to see to be has something influencing.

Show 2 more comments

1 answer

-1

It looks like a margin problem / fill, try to set the cardUseCompatPadding attribute to true. For example:

<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="6dp"
    card_view:cardUseCompatPadding="true"
    card_view:cardElevation="4dp"
    card_view:cardCornerRadius="3dp">

Explanation of Android doc:

Cardview adds additional padding to draw shadows on platforms before L.

This can cause Cards to have different sizes between L and before L. If you need to align Cardview with other views, you may need features specific dimension version of the API to explain the changes. Alternatively, you can set the cardUseCompatPadding flag to true and Cardview will add the same fill values on L platforms and then.

Since the creation of the cardUseCompatPadding flag the truth adds unnecessary gaps in the user interface, the default value is false.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.