Setting Elevation in XML on AppCompat CardView on Android 5.0

后端 未结 5 2076
梦如初夏
梦如初夏 2020-12-12 16:07

From what I understand, early in the preview stage there seemed to be no way to set elevation in XML only on CardViews without a hack in Java. Now that the offi

5条回答
  •  星月不相逢
    2020-12-12 16:41

    It looks like a margin/padding problem, try to set the cardUseCompatPadding attribute to true. E.g.:

    
    

    Explanation from Android doc :

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

    This may cause Cards to have different sizes between L and before L. If you need to align CardView with other Views, you may need api version specific dimension resources to account for the changes. As an alternative, you can set cardUseCompatPadding flag to true and CardView will add the same padding values on platforms L and after.

    Since setting cardUseCompatPadding flag to true adds unnecessary gaps in the UI, default value is false.

提交回复
热议问题