Why there is no space between CardViews on Lollipop?

前端 未结 4 540
小鲜肉
小鲜肉 2021-01-30 06:26

I try to use the CardView and it works well below 5.0, but looks strange on Lollipop.

\"enter

4条回答
  •  野的像风
    2021-01-30 06:41

    You have to add app:cardUseCompatPadding="true" to your Cardview. But just adding that may give you an error. To avoid that error, you also have to add xmlns:app="http://schemas.android.com/apk/res-auto" to your CardView.

    For example,

    
    
        // Other views here
    
    
    

    Some would add card_view:cardUseCompatPadding="true" and xmlns:card_view="http://schemas.android.com/apk/res-auto" instead of those mentioned above. Both ways are correct.

    If you want to know more about app in XML(Android), please go through this answer :

    Although previous answers will solve the problem, they didn't explain what each attribute does. So to be more helpful to answer seekers,

    cardPreventCornerOverlap attribute adds padding to CardView on v20 and before to prevent intersections between the Card content and rounded corners.

    cardUseCompatPadding attribute adds padding in API v21+ as well to have the same measurements with previous versions.

提交回复
热议问题