Cardview - white border around card

前端 未结 4 1516
忘掉有多难
忘掉有多难 2020-12-13 06:54

I am using a cardview as the root of a custom view I am writing. I using the v7 support library. My XML looks like this:



        
4条回答
  •  一向
    一向 (楼主)
    2020-12-13 07:24

    I might be late in the game, but I had the same issue. Just wanted to share a simple solution!

    My custom view extended a CardView and I had a margin applied to the root element (i.e. CardView) in the XML just like in the original question. This ended up giving me the extra white border like this:

    Solution was to move the margin from root of the Custom View XML to the declaration of your custom view (check comments in the snippet)

    Code snippet:

    
        app:cardElevation="@dimen/default_card_elevation">
    
        
            .
            .
            .
    
    

    Ended up just moving over the margin to my custom view declaration which got rid of the extra white border:

    
            cv:pt_widgetColor="@color/colorAccent" />
    

    After the change, much cleaner :) :

提交回复
热议问题